我正在使用引用来改变数组:
foreach($uNewAppointments as &$newAppointment)
{
foreach($appointments as &$appointment)
{
if($appointment == $newAppointment){
$appointment['index'] = $counter;
}
}
$newAppointment['index'] = $counter;
$newAppointments[$counter] = $newAppointment;
$counter++;
}
Run Code Online (Sandbox Code Playgroud)
如果我打印数组内容,那么我会收到预期的结果.当我迭代它时,所有元素似乎都是相同的(第一个).
当我删除引用运算符&在内部数组中时,除了未设置索引外,一切正常.