Re: Array function to delete

From: Date: Thu, 25 Apr 2002 20:44:30 +0000
Subject: Re: Array function to delete
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-94655@lists.php.net to get a copy of this message
On Thursday, April 25, 2002, at 04:27 PM, Liam Gibbs wrote:
Thanks for all your help, everyone, but both suggestions (unset and array_slice) pretty much didn't improve on my current way. I was jsut trying to find a faster way, but unset doesn't seem to be working properly (but I'll need to fiddle more) and the array_slice way is just too intensive. for($counter = 0; $counter < count($listitems); $counter++) { if($listitems[$counter] != $item) $newlist .= ",$listitems[$counter]"; } $newlist = substr($newlist, 1, strlen($newlist)); $listitems = explode("," $newlist);
Why not just do $newlistitems = array(); // initialize variable foreach ($listitems as $listitem) { if ($listitem != $item) { $newlistitems[] = $listitem; } } This gives you an array called $newlistitems. Each element in $newlistitems is an element from the old $listitems that does not match $item. Erik ---- Erik Price Web Developer Temp Media Lab, H.H. Brown pricee@hhbrown.com

« previous php.general (#94655) next »