reindexing an array after unset()
| From: | Erik Price | Date: | Wed, 08 May 2002 19:23:00 +0000 |
| Subject: | reindexing an array after unset() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-96631@lists.php.net to get a copy of this message | ||
After using unset() on an array element to remove it, what is the best way to reindex the array so that I have a nice sequential order of 0, 1, 2, 3... again? (Otherwise, unset($array[2]) will leave me with an array that looks like 0, 1, 3...).
There's a bunch of ways to do it, but I'm curious which is the fastest. It strikes me that I could just implode the array and explode it again, assigning the result back to the original array reference. What do you think?
Thanks,
Erik
----
Erik Price
Web Developer Temp
Media Lab, H.H. Brown
pricee@hhbrown.com