这些阵列有没有办法
$array1 = array(
'21-24' => array(
'1' => array("...")
)
);
$array2 = array(
'21-24' => array(
'7' => array("..."),
)
);
$array3 = array(
'25 and over' => array(
'1' => array("...")
)
);
$array4 = array(
'25 and over' => array(
'7' => array("...")
)
);
要合并到哪个结果到下面的数组?
array(
'21-24' => array(
'1' => array("..."),
'7' => array("...")
),
'25 and over' => array(
'1' => array("..."),
'7' => array("...")
)
);
注意:
我尝试使用array_merge_recursive()这样的
$x = array_merge_recursive($array1, $array2);
$x = array_merge_recursive($x, $array3);
$x = array_merge_recursive($x, $array4);
但结果是
array(
'21-24' => array(
'1' => array("..."),
'2' => array("...")
),
'25 and over' => array(
'1' => array("..."),
'2' => array("...")
)
);
答案 0 :(得分:25)
您考虑过array_replace_recursive()
吗?
print_r(array_replace_recursive($array1, $array2, $array3, $array4));