|
|
|
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
<?
/*
* 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
| |
|
|
|