PHP Modify an Array within an Array -
i created array , put array inside array. modify array, code never modify it.
here create part:
$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 row....... $arr_row_name[] = $arr_slot_name; }
here part try access array , modify it.
$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"; } }
in second bit of code, change:
$arr_slot_name = $arr_row_name[$x];
to:
$arr_slot_name = &$arr_row_name[$x];
the way have it, making copy of $arr_row_name[$x]
$arr_slot_name
... in second option, assigning reference , able change original ...
Comments
Post a Comment