我想合併兩個數組,其中主鍵匹配,我試着使用array_merge但密鑰剛剛被覆蓋。PHP合併兩個數組,其中鍵匹配
例如,我有此數組:
$date = '2017-08-01';
$price_arr_1 = array();
$price_arr_1[$date]['adult_1'] = 10;
$price_arr_1[$date]['child_1'] = 2;
print_r($price_arr_1);
,其輸出:
Array ([2017-08-01] => Array ([adult_1] => 10 [child_1] => 2))
我有此數組:
$date = '2017-08-01';
$price_arr_2 = array();
$price_arr_2[$date]['adult_2'] = 10;
$price_arr_2[$date]['child_2'] = 2;
print_r($price_arr_2);
,其輸出:
Array ([2017-08-01] => Array ([adult_2] => 10 [child_2] => 2))
當我試圖把它們合併是這樣的:
print_r(array_merge($price_arr_1,$price_arr_2));
它輸出這樣的:
Array ([2017-08-01] => Array ([adult_2] => 10 [child_2] => 2))
我要輸出這樣的:
Array ([2017-08-01] => Array ([adult_1] => 10 [adult_2] => 10 [child_1] => 2 [child_2] => 2))
知道的任何想法,如何達到上述目的!