Php Programming Code Examples
Php > Arrays Code Examples
Array Insertion
Array Insertion
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 ;
}
}
/*
* class arrayAll ends here