PHP's documentation for foreach states that if you iterate by reference [foreach ($ii as &$i) ...], you should unset $i after the loop. $i still points to the last element of the array - updating $i or reusing it will update the last element of the array.

In short, why doesn't PHP automatically unset $i after the loop? I can't think of too many cases where you would want to hold on to that reference after you exit the loop, but I can think of a lot of scenarios where a user could accidentally tamper the array by using $i in a different context later on (especially since loop variable names often are reused).

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to