Re: Reindexing Arrays

From: Date: Thu, 15 Feb 2001 17:10:24 +0000
Subject: Re: Reindexing Arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-39947@lists.php.net to get a copy of this message
Try this : <?php $foo = array('a','b','c'); unset($foo[1]); print_r($foo); // [0] => a [2] => c $bar = array('a','b','c'); $piece = array_splice ($bar, 1 ,1); print_r($piece); // [0] => b print_r($bar); // [0] => a [1] => c ?> http://www.php.net/manual/en/function.array-slice.php http://www.php.net/manual/en/function.unset.php Regards, Philip On Thu, 15 Feb 2001, Nathan Cassano wrote: > I have an array of search results which I am searching through and > unset()ing unwanted search results. My question is once I have unset a > result there is then a break in the numeric index and how do I stop this > from happening or reindex the results. Like this.. > > $results = array(0 => array(more elements...), 1 => array(bla bla...) , 2 > =>array(....)); > > /* unset results index 1 */ > unset($results[1]); > > /* > > Now the $results index is like this.. > > array(0 => array(more elements...), 2 =>array(....)); > > */ > > > -- > 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 >

« previous php.general (#39947) next »