Re: delete array item and resort

From: Date: Wed, 05 Dec 2001 16:50:33 +0000
Subject: Re: delete array item and resort
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-76740@lists.php.net to get a copy of this message
$array = array("a","b","c"); print_r($array); unset($array[1]); print_r($array); $array = array_values($array); print_r($array); ------ produces.... Array ( [0] => a [1] => b [2] => c ) Array ( [0] => a [2] => c ) Array ( [0] => a [1] => c ) Jim
what is the easiest way to delete an array element and then resort the array so the elements receive the correct numbering. I was thinking something like this: $itemArray = array("red","blue","yellow"); delete("$itemArray[1]"); so key 0 is still "red" but key 2 is still yellow but is remembered to become key 1. Hopefully that makes sense, get rid of one item in the middle and the rest of the array moves up one position. Thanks, » Michael Krisher mike@hyperquake.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
-- Jim Musil --------- Multimedia Programmer Nettmedia ------------- 212-629-0004 jim@nettmedia.com

« previous php.general (#76740) next »