【发布时间】:2010-12-03 08:35:01
【问题描述】:
我正在使用引用来改变数组:
foreach($uNewAppointments as &$newAppointment)
{
foreach($appointments as &$appointment)
{
if($appointment == $newAppointment){
$appointment['index'] = $counter;
}
}
$newAppointment['index'] = $counter;
$newAppointments[$counter] = $newAppointment;
$counter++;
}
如果我打印数组内容,那么我会收到预期的结果。当我迭代它时,所有元素似乎都是相同的(第一个)。
当我删除内部数组中的引用运算符 & 时,一切正常,除了未设置索引。
【问题讨论】:
-
我怀疑你在某处重复使用了一个引用变量,忘记了它仍然是一个引用。查看其余代码可能会有所帮助
标签: php loops foreach pass-by-reference