Re: Re: reindexing an array after unset()
| From: | Nathan | Date: | Wed, 08 May 2002 19:41:00 +0000 |
| Subject: | Re: Re: reindexing an array after unset() | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-96636@lists.php.net to get a copy of this message | ||
THAT's it!!! I've been trying to figure out why the hell I put that into a chunk of code I
wrote a
few months ago! :-)
What you can do, and the fastest way I know to do it (which certainly isn't saying something,
but...) is to push a dummy value on the end of the array, get rid of the elements you don't
want,
then pop the dummy value off the end of the array.
The side effect of doing this is that the array gets re-keyed sequentially for you.
Looks like:
// $array has 5 keys
array_push("dummy", $array); // adds key #6
unset($array[3]); // you get 0,1,2,4,5
array_pop($array); // you get 0,1,2,3
Make sense? Anyone have a faster way to do this?
----- Original Message -----
From: "Kyle Gibson" <admin@plaguenet.com>
To: <php-general@lists.php.net>
Sent: Wednesday, May 08, 2002 1:28 PM
Subject: [PHP] Re: reindexing an array after unset()
> What do you think?
Try
array_pop($array);
http://www.php.net/manual/en/function.array-pop.php
-Kyle
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php