Re: Looping through arrays with foreach
- From: "Richard Levasseur" <richardlev@xxxxxxxxx>
- Date: 31 Mar 2006 08:22:38 -0800
It should be said that foreach operates on a copy of the array.
Changes to $value won't will not affect the original array.
With PHP5, the referential foreach was added, which aliases $value to
the original value in the array.
foreach($array as $key => & $value) { ... }
It should also be noted that $value will still exist as a reference
after the foreach() is over, thus assignments to $value will affect the
array also, so you much unset() it to prevent undesired side effects.
More information is available in the manual at:
http://us2.php.net/manual/en/control-structures.foreach.php
.
- References:
- Looping through arrays with foreach
- From: Sjoerd
- Looping through arrays with foreach
- Prev by Date: Re: Strict types
- Next by Date: Re: Strict types
- Previous by thread: Re: Looping through arrays with foreach
- Next by thread: Re: Looping through arrays with foreach
- Index(es):
Relevant Pages
|