note 9728 added to array_slice
| From: | hb at waldorf-gmbh dot de | Date: | Tue, 21 Nov 2000 11:47:01 +0000 |
| Subject: | note 9728 added to array_slice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-7943@lists.php.net to get a copy of this message | ||
if you want to "securely" remove an element of an array ....
$objects =
array('first','second','third','fourth','fifth','sixth','seventteen');
function remove_element($array, $left_id, $right_id) // Remove Element
// left_id is element position(counts from 1)
// right_id array position (counts from 0)
{
$left = array_slice ($array, 0, $left_id);
$right = array_slice ($array, $right_id);
$array = array_merge ($left, $right);
unset ($left);
unset ($right);
return $array;
}
// just give both information of the element you want to remove.
// if youi want to remove the third element transmit the array
// position (2) and the "real" position (3) to the function,
// and the element is gone ...
$objects = remove_element($objects, 2,3);
http://www.php.net/manual/function.array-slice.php