ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> php-general
php-general
Re: [PHP] foreach / unset
by Brent Baisley other posts by this author
Oct 28 2005 5:34AM messages near this date
Re: [PHP] foreach / unset | Re: [PHP] foreach / unset
The foreach statement works because you are getting the array index  
($k) to unset the array item. I think somewhere in the manual it says  
it's unsafe because some people might think you could just use unset 
($v) to unset the array item. Which wouldn't work because $v is more  
of a temporary variable and not a reference to the array item.

On Oct 27, 2005, at 6:18 PM, Richard Lynch wrote:

>  Somewhere in the manual (damned if I can find it now) it says (or used
>  to say) that you can or can't safely do this:
> 
>  while (list($k, $v) = each($array)){
>    if (...) unset($array[$k]);
>  }
> 
>  I don't even remember if it's safe or not, but I swear I saw it not
>  that long ago...
> 
>  Anyway, can you do *this* safely as a DOCUMENTED FEATURE:
> 
>  foreach($array as $k => $v){
>    if (...) unset($array[$k]);
>  }
> 
>  I'm sure I could test it and maybe find out if "it works" but is it
>  documented behaviour I can rely on?  I'm sure not finding this in the
>  manual now that I go looking for it, though I know I saw it there
>  before.
> 
>  PS
>  I'm being dragged kicking and screaming into using this new-fangled
>  'foreach' thing instead of while/list/each, and I don't really care
>  for it so far. :-)
> 
>  -- 
>  Like Music?
>  http://l-i-e.com/artists.htm
> 
>  -- 
>  PHP General Mailing List (http://www.php.net/)
>  To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 

-- 
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thread:
Richard Lynch
Bogdan Ribic
John Nichel
Jochem Maas
Richard Lynch
Brent Baisley
Jochem Maas
Niels Ganser
Karlos Zafra

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved