我使用引用来改变一个数组:与PHP数组意外行为参考
foreach($uNewAppointments as &$newAppointment)
{
foreach($appointments as &$appointment)
{
if($appointment == $newAppointment){
$appointment['index'] = $counter;
}
}
$newAppointment['index'] = $counter;
$newAppointments[$counter] = $newAppointment;
$counter++;
}
如果我打印数组内容,然后我收到了预期的结果。当我遍历它时,所有元素似乎都是相同的(第一个)。
当我删除内部数组中的参考运算符&时,除非未设置索引,否则一切正常。
我怀疑你在某处重新使用了一个引用变量,忘记它仍然是一个引用。看到其他的代码可能会有所帮助 – Greg 2009-10-02 14:55:58