|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-06-04 12:47 UTC] michael at chunkycow dot com dot au
[2007-06-04 22:02 UTC] dmtr79 at yahoo dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 17 07:00:01 2025 UTC |
Description: ------------ foreach seems to run in different ways when called globally and from a function. As it can be understood from the documentation, foreach shouldn't touch an original array and operate with its copy instead. But at least, one could expect its behaviour to be similar for the 2 cases described in code. Reproduce code: --------------- $array = array(1, 2); function test() { global $array; foreach ($array as $a) foreach ($array as $b) echo "$a $b\n"; } foreach ($array as $a) foreach ($array as $b) echo "$a $b\n"; echo "---\n"; test(); Expected result: ---------------- 1 1 1 2 2 1 2 2 --- 1 1 1 2 2 1 2 2 Actual result: -------------- 1 1 1 2 2 1 2 2 --- 1 1 1 2