Re: Deleting elements from the middle of an array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux