WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Array Insertion
Categories : PHP, PHP Classes, Arrays Click here to Update Your Picture
Saravanan .R
Date : Sep 30th 2004
Grade : 3 of 5 (graded 6 times)
Viewed : 6632
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Saravanan .R
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

Class Name : arrayAll

Function Name : Insert()

Args : 1. <$array> Designation Array
2. <$position> Position to be Insertion
3. <$elements> Elements to be Inserted into the Array

Task : Inserting the No. of Elements in the given Array Postion.

<?php
class arrayAll
{
    var
$startError = '<p><b>Warning:</b> Check your input parameters <i><b>';
    var
$endError = '</b></i></p>';

    function
Insert($array = '', $position = '' , $elements= '')           
    {
        if (
$position == '' || $array == '' || $elements == '' || $position < 1 || $position > count($array)+1)
        {
            echo
$this->startError . "insert".$this->endError;
        }
        else
        {
           
$left = array_slice ($array, 0, $position+1);
           
$right = array_slice ($array, $position+1,count($array));

                for(
$i=1; $i< COUNT($elements) ; $i++)
                {
                       
$insert[$i] .= $elements[$i]  ;
                }               
           
$array = array_merge ($left, $insert, $right);
           
// echo " Left Count : " . COUNT($left) . "<BR>\n";
            // echo " Insert Count : " . COUNT($insert) . "<BR>\n";
            // echo " Right Count : " . COUNT($right) . "<BR>\n";
           
unset($left, $right, $insert);
        }
        unset (
$position, $elements);
        return
$array ;
    }
}
?>



HTML_Graphs uses PHP to provide a consistent interface for creating HTML based charts. The user of the class sets up arrays that are passed to html_graph() which then takes care of all the messy HTML layout.
Categories : Graphics, Arrays, PHP, PHP Classes, Charts and Graphs
Matrix Class (PHP5 and up)
Categories : PHP, PHP Classes, Arrays
PHPDRAW, the php wannabe Photoshop ;-)
Categories : PHP, PHP Classes, GD image library, Arrays
Compare two texts and display a block of text with the differences between them.
Categories : PHP, PHP Classes, Filesystem, Strings, Arrays
Sort the results from a SELECT query (any number of columns) into an array automatically.
Categories : PHP, PHP Classes, Arrays, Databases, MySQL
A class to put get and post variables in hidden form elements. Works on scalars, normal arrays, associative arrays.
Categories : Algorithms, Variables, Arrays, PHP, PHP Classes
Tweak Array, insert/add elements to any position of your arrays - delete elements from your arrays - move elements within your arrays - replace elements from your arrays ... the array, 'dynamically' grows or shrinks to whatever we tweak it.
Categories : PHP Classes, Arrays, PHP
XML To Array
Categories : PHP, PHP Classes, XML, Arrays
very simple ftp class
Categories : PHP, PHP Classes, FTP
Authorize.net AIM Interface Class v1.0.0
Categories : PHP, PHP Classes, Ecommerce, Payment Gateways
Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
Array values from javascript to php
Categories : PHP, Java Script, Arrays
News management class
Categories : PHP, PHP Classes, Beginner Guides
A Timing Class
Categories : PHP, PHP Classes, Date Time
The class to check load time of your script VERY usefull for relatively slow applications, but not only..
Categories : PHP, PHP Classes, Debugging
 Joseph Crawford wrote : 1197
nice code now all you need to do is to implement a way to check for duplicate array entries because if there is a duplicate wont it leave the entry out or something?

what if the user wanted duplicates?
 
 Saravanan .R wrote : 1206
Thanx Joseph. for your comment. Now I have comeup with  solution for your comment. check it out.
 
 Saravanan .R wrote :1207
&lt;?
/*
 *  Class Name : arrayAll
 *    
 *    Function Name : Insert()
 *
 *        Args      : 1. &lt;$array&gt; Designation Array
 *                    2. &lt;$position&gt; Position to be Insertion
 *                    3. &lt;$elements&gt; Elements to be Inserted into the Array
 *                    4. &lt;$preserveDuplicate&gt; Preserve the Duplicate values [ yes/no ]
 *
 *        Returns   : nothing
 *
 *        Task      : Inserting the No. of Elements in the given Array Postion.
 *
 *        Docs      : Yes
 *
 *****************************************************************************/

class arrayAll
{
    var $startError = `&lt;p&gt;&lt;b&gt;Warning:&lt;/b&gt; Check your input parameters &lt;i&gt;&lt;b&gt;`;
    var $endError = `&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;`;

    function Insert($array = ``, $position = `` , $elements= ``, $preserveDuplicate=`no`)            
    {
        if ($position == `` || $array == `` || $elements == `` || $position &lt; 1 || $position &gt; count($array)+1)
        {
            echo $this-&gt;startError . "insert". $this-&gt;endError;
        }
        else
        {
            $fullArray ="";

            $left = array_slice ($array, 0, $position-1);
            $right = array_slice ($array, $position,count($array));

            if ( strtolower($preserveDuplicate) == "yes" )
            {
                for( $lft =0 ; $lft &lt; $position ; $lft++)
                {
                    $fullArray[] = $array[$lft] ;
                }

                for( $mdl=0 ; $mdl &lt; count($elements); $mdl++)
                {
                    $fullArray[] = $elements[$mdl] ;
                }

                for( $rght = 0 ; $rght &lt; COUNT($right) ; $rght++)
                {
                    $fullArray[] = $right[$rght] ;
                }
            }
            else
                $fullArray = array_merge($left, $elements, $right);


            unset($left, $right, $insert);
        }
        unset ($position, $elements);
        return $fullArray ;
    }

/* 
 *    class arrayAll ends here 
 *****************************************************************************/

Here I have introduce the 4th argument, User can enable to preserve duplicate.
any suggestion or feedback u may mail me : saravanan.r@gmail.com

Thanks
Saravanan.R