6
PHP Foreach通过参考传递:最后一个元素重复吗?(臭虫?)
我刚编写的简单php脚本有一些非常奇怪的行为。我将其减少到重新创建该错误所需的最低限度: <?php $arr = array("foo", "bar", "baz"); foreach ($arr as &$item) { /* do nothing by reference */ } print_r($arr); foreach ($arr as $item) { /* do nothing by value */ } print_r($arr); // $arr has changed....why? ?> 输出: Array ( [0] => foo [1] => bar [2] => baz …