Is there a way for these arrays
$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("...")
)
);
to be merged which result into the array below?
array(
'21-24' => array(
'1' => array("..."),
'7' => array("...")
),
'25 and over' => array(
'1' => array("..."),
'7' => array("...")
)
);
NOTE:
I tried using array_merge_recursive() like this
$x = array_merge_recursive($array1, $array2);
$x = array_merge_recursive($x, $array3);
$x = array_merge_recursive($x, $array4);
but it resulted in
array(
'21-24' => array(
'1' => array("..."),
'2' => array("...")
),
'25 and over' => array(
'1' => array("..."),
'2' => array("...")
)
);
Have you considered array_replace_recursive()
?
print_r(array_replace_recursive($array1, $array2, $array3, $array4));