|
Posted by Richard Levasseur on 03/31/06 19:22
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
Navigation:
[Reply to this message]
|