Re: reindexing an array after unset()

From: Date: Wed, 08 May 2002 19:35:13 +0000
Subject: Re: reindexing an array after unset()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-96634@lists.php.net to get a copy of this message
Try array_values() or array_splice() Regards, Philip Olson On Wed, 8 May 2002, Erik Price wrote: > 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 > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#96634) next »