ID: 50161 Updated by: j...@php.net Reported By: marc at perkel dot com -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: Linux PHP Version: 5.2.11 New Comment:
Already reported several times, already decided to be the correct behavior which is also documented. Previous Comments: ------------------------------------------------------------------------ [2009-11-12 20:45:33] marc at perkel dot com Description: ------------ When using foreach and looping through an array the second time if the index variable isn't unset the results are that the referenced variables is used as the index rather than the named variable. The issue can be solved if when the foreach is set up that it does an unset on the variable passed as the "as" variable. PHP should be changed to unset the parameter passed as the index into the array. Reproduce code: --------------- $myarray = array("one","two","three","four"); foreach ($myarray as &$x) { $x = "$x -"; print "$x\n"; } print "\n"; foreach ($myarray as $x) { print "$x\n"; } Expected result: ---------------- one - two - three - four - one - two - three - four - Actual result: -------------- one - two - three - four - one - two - three - three - ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50161&edit=1