【发布时间】:2013-04-26 22:20:20
【问题描述】:
当我写了一些代码时,PHP 让我有些困惑,因为我没想到以下代码的结果:
$data = array(array('test' => 'one'), array('test' => 'two'));
foreach($data as &$entry) {
$entry['test'] .= '+';
}
foreach($data as $entry) {
echo $entry['test']."\n";
}
我觉得应该输出
one+
two+
但是结果是:http://ideone.com/e5tCsi
one+
one+
谁能解释一下为什么?
【问题讨论】:
标签: php loops foreach pass-by-reference