|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-09-24 09:58 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2016-09-24 09:58 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 14 09:00:02 2025 UTC |
Description: ------------ The first foreach changes the value by reference of each entry by adding the digit "2". The next foreach dumps each key with its entry. We can see that the last entry is equal to "titi2" and not "tutu2" (so it appears to be equal to the previous entry). The last commented out foreach demonstrates that if the var used for the entry is different ($val <> $val2), then there's no bug. But you must comment out the second foreach first. Test script: --------------- <?php $a = [ 'toto', 'titi', 'tutu', ]; foreach ($a as $key => &$val) $val .= '2'; foreach ($a as $key => $val) var_dump($key, $val); // foreach ($a as $key => $val2) // var_dump($key, $val2); Actual result: -------------- int(0) string(5) "toto2" int(1) string(5) "titi2" int(2) string(5) "titi2"