我创建了一个数组,并将该数组放入另一个数组中。我现在想修改Array,但代码从未修改过它。
这是创建部件:
$arr_row_name = array();
for($nrow=0;$nrow < $numRows;$nrow++)
{
$arr_slot_name = array();
for($nsp=0;$nsp < $numServProvider + 1;$nsp++)
{
$arr_slot_name[] = "Closed";
}
//Add Slot to the row.......
$arr_row_name[] = $arr_slot_name;
}
这是我尝试访问数组并对其进行修改的部分
$arr_row_length = count($arr_row_name);
for($x=0;$x<$arr_row_length;$x++)
{
$arr_slot_name = $arr_row_name[$x];
$arr_slot_length = count($arr_slot_name);
for($slot=0;$slot<$arr_slot_length;$slot++)
{
$arr_slot_name[$slot] = "Open";
}
}
在您的第二位代码中,更改:
$arr_slot_name = $arr_row_name[$x];
至:
$arr_slot_name = &$arr_row_name[$x];
按照你的方式,你正在将$arr_row_name[$x]
复制到$arr_slot_name
。。。在第二个选项中,您通过引用指定它,并且可以更改原始。。。