note 39993 deleted from function.array-slice by betz
| From: | betz@php.net | Date: | Sun, 23 May 2004 09:14:29 +0000 |
| Subject: | note 39993 deleted from function.array-slice by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69984@lists.php.net to get a copy of this message | ||
Note Submitter: adamplumb@comcast.net
----
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.