NYCPHP Meetup

NYPHP.org

[nycphp-talk] Unsetting array elements

Aaron Fischer agfische at email.smith.edu
Fri Oct 20 15:48:49 EDT 2006


I fixed that line and it's working now:

else { unset($test[$k]); }

However I would be interested to hear if anyone thinks there is a better 
or more efficient approach to how I am doing it.

Cheers,

-Aaron


Aaron Fischer wrote:
> Hi,
> 
> I'd like to cycle through an array and destroy some elements (and leave 
> some intact).  What's the "best" way to do that?
> 
> Here's what I put together so far (which shows my array ignorance)  =)
> 
> <?
> 
> $test=array("auth" => "yes" , "name" => "joe" , "sort" => "ascending")
> 
> while (list ($k, $v) = each ($test))
> 	{
> 		if ($k == "auth") {}
> 		else { unset($k[$v]); }
> 	}
> 
> ?>
> 
> That produces an error because of the unset($k[$v]; line.
> 
> Thanks!
> 
> -Aaron
> _______________________________________________



More information about the talk mailing list