Cannot use a scalar value as an array in C:\xampp\htdocs\testing\check_array.php on line 12
见下面的程序:
<?php
$array=array(1,2,3,3);
$array_second=array(2,4,3,6);
$result_array=array();
for($start=0;$start<count($array);$start++)
{
$result_array[$start]=$array[$start];
for($start_second=0;$start_second<count($array_second);$start_second++)
{
$result_array[$start][$start_second]=$array_second[$start_second];
}
}
print_r($result_array);
?>
请告诉我我做错了什么? 对我来说真的很有帮助
答案 0 :(得分:0)
<?php
$array = array(1, 2, 3, 3);
$array_second = array(2, 4, 3, 6);
$result_array = array();
for ($start = 0; $start < count($array); $start++) {
// $result_array[$start] should be array, not scalar!
// $result_array[$start] = $array[$start];
for ($start_second = 0; $start_second < count($array_second); $start_second++) {
// this line caused the error, cant do 0[1] = 5
$result_array[$start][$start_second] = $array_second[$start_second];
}
}
var_dump($result_array);