note 16963 added to function.array-slice
| From: | danstowellEATINGSPAM at php2 dot chek dot com | Date: | Tue, 20 Nov 2001 14:14:08 +0000 |
| Subject: | note 16963 added to function.array-slice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-21062@lists.php.net to get a copy of this message | ||
Someone above wrote a function for removing one single element from an array. It is too slow for my
purposes, instead just write this one line:
$myarray = array_merge(array_slice($myarray,0,$i),array_slice($myarray,$i+1));
It completely removes element number $i from the array $myarray - the elements with higher numbers
will be shunted down one.
(NB - just using unset() leaves an empty array element and doesn't 'shunt'.)
--
http://www.php.net/manual/en/function.array-slice.php
http://master.php.net/manage/user-notes.php?action=edit+16963
http://master.php.net/manage/user-notes.php?action=delete+16963
http://master.php.net/manage/user-notes.php?action=reject+16963