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 Matrix Class (PHP5 and up) Categories : PHP , PHP Classes , Arrays 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 Sort the results from a SELECT query (any number of columns) into an array automatically. Categories : PHP , PHP Classes , Arrays , Databases , MySQL 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 XML To Array Categories : PHP , PHP Classes , XML , Arrays Compare two texts and display a block of text with the differences between them. Categories : PHP , PHP Classes , Filesystem , Strings , 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 Three Cool Classes and One Trick Categories : PHP , PHP Classes , Graphics , Email Print out array key => value in colored HTML Categories : PHP , Arrays , HTML and PHP Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP , Arrays , Date Time , Databases , MySQL Specify your connection settings and create a link to a MySQL database. Categories : PHP , PHP Classes , Databases , MySQL , Beginner Guides Link Submition - Allow your visitors to submit links to the site. Categories : PHP , Arrays , Filesystem , Beginner Guides Class: Info on Users, Servers and the running script Categories : PHP , Classes and Objects , User Interface , PHP Classes Variable serialization and unserialization. Loading and saving variable structures
to and from file. Categories : Arrays , Filesystem , Variables , Strings , PHP
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
<?
/*
* 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
* 4. <$preserveDuplicate> 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 = `<p><b>Warning:</b> Check your input parameters <i><b>`;
var $endError = `</b></i></p>`;
function Insert($array = ``, $position = `` , $elements= ``, $preserveDuplicate=`no`)
{
if ($position == `` || $array == `` || $elements == `` || $position < 1 || $position > count($array)+1)
{
echo $this->startError . "insert". $this->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 < $position ; $lft++)
{
$fullArray[] = $array[$lft] ;
}
for( $mdl=0 ; $mdl < count($elements); $mdl++)
{
$fullArray[] = $elements[$mdl] ;
}
for( $rght = 0 ; $rght < 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