Re: Deleting elements from the middle of an array

From: Date: Tue, 15 Mar 2011 16:55:03 +0000
Subject: Re: Deleting elements from the middle of an array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-311877@lists.php.net to get a copy of this message
At 4:31 PM -0400 3/14/11, Paul M Foster wrote:
Here's what I need to do: I have an indexed array, from which I need to delete elements in the middle. Once completed, the indexes should be numerically in sequence, as they were when I first encountered the array. That is: Before: $arr = array(0 => 5, 1 => 6, 2 => 7, 3 => 8, 4 => 9, 5 => 10); After: $arr = array(0 => 5, 1 => 6, 2 => 9, 3 => 10); I've tried: 1) Using for() with unset(). Elements are deleted, but the indexes are no longer sequential.
Try shuffle() -- that will assign new indexes to the new array. Cheers, tedd -- ------- http://sperling.com/

« previous php.general (#311877) next »