[nycphp-talk] Unsetting array elements
Aaron Fischer
agfische at email.smith.edu
Fri Oct 20 16:02:07 EDT 2006
Thanks Ken. Unfortunately I figured that out AFTER I sent the original
question. =)
-Aaron
Ken Robinson wrote:
> At 03:17 PM 10/20/2006, 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.
>
>
>
> You need to unset the index in the test array not in the $k array, so
> the unset line should look like:
> else unset($test[$k]);
>
> Ken
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
More information about the talk
mailing list