note 39993 added to function.array-slice
| From: | adamplumb at comcast dot net | Date: | Tue, 17 Feb 2004 21:13:21 +0000 |
| Subject: | note 39993 added to function.array-slice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-65324@lists.php.net to get a copy of this message | ||
I've been looking for a function where you could just delete one element of an array and keep
the rest in check. Since I couldn't find it I decided to write it myself. This function
preserves the rest of the array perfectly(keys and all).
function deleteElement($arr, $offset)
{
$ii = 0;
foreach($arr AS $key=>$val)
{
if($ii != $offset)
$tmp[$key] = $val;
$ii++;
}
return $tmp;
}
$a = Array("a", "b", "c", "d", "e");
$b = deleteElement($a, 2);
Output of $b will result in "c" being gone from the array.
----
Manual Page -- http://www.php.net/manual/en/function.array-slice.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39993
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39993&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39993&report=yes
Search -- http://master.php.net/manage/user-notes.php