note 21178 added to function.array-splice
| From: | brettbeeson at hotmail dot com | Date: | Thu, 02 May 2002 01:10:00 +0000 |
| Subject: | note 21178 added to function.array-splice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-30070@lists.php.net to get a copy of this message | ||
Further to andrei's note on removing an element. Previous code assumes element exists.
Instead, try :
// Removes an element with $key in $array, if it exists.
function array_remove($key,&$array) {
if (key_exists($key,$array)) {
$key_index = array_keys(array_keys($array), $key);
array_splice($array, $key_index[0], 1);
}
}
--
http://www.php.net/manual/en/function.array-splice.php
http://master.php.net/manage/user-notes.php?action=edit+21178
http://master.php.net/manage/user-notes.php?action=delete+21178
http://master.php.net/manage/user-notes.php?action=reject+21178