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
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
Mobile Dev World

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 7 times)
Viewed : 9354
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 ;
    }
}
?>



PHPDRAW, the php wannabe Photoshop ;-)
Categories : PHP, PHP Classes, GD image library, Arrays
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
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
Matrix Class (PHP5 and up)
Categories : PHP, PHP Classes, Arrays
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
Compare two texts and display a block of text with the differences between them.
Categories : PHP, PHP Classes, Filesystem, Strings, Arrays
XML To Array
Categories : PHP, PHP Classes, XML, Arrays
Client classes for Dictionary servers UPDATED: 2000-06-06
Categories : Network, Search, Complete Programs, PHP Classes, PHP
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
Class that allows the PHP developer to create and manage UNIX like password files suitable for use as Apache authentication password files.
Categories : HTTP, PHP, PHP Classes, Filesystem
A File Browser Class.To Read Drives,Directories and Files .Files writing is also possible
Categories : PHP, PHP Classes, Filesystem
crop and resize image class using gd library function
Categories : PHP, PHP Classes, GD image library, Graphics
Vote-Poll script that has a wrapper class that allows the user to create multiple polls on the same page with little trouble.
Categories : PHP, PHP Classes, HTML and PHP
3 lines of Code to extract Tar, Zip, Gzip etc..
Categories : PHP, Filesystem, PHP Classes, Compression
 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