note 53714 added to ref.array
| From: | spam at afoyi dot com | Date: | Fri, 10 Jun 2005 05:35:10 +0000 |
| Subject: | note 53714 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90209@lists.php.net to get a copy of this message | ||
I've been trying to find a clean way of removing an element from the middle of an indexed array
and having all the elements above it "fall down" to fill in the gap. There's no
array_delete function, only array_(pop|push|shift|unshift).
According to the page for array_merge if it is given a single array then it will be re-indexed.
Using that information the following simple function does what I wanted:
<?php
function my_array_delete($array, $item) {
if (isset($array[$item]))
unset($array[$item]);
return array_merge($array);
}
?>
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+53714
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53714&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53714&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53714&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53714&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53714&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+53714&report=yes
Search -- http://master.php.net/manage/user-notes.php