說我有一個相同的結構,像這樣一對夫婦多維動數組:PHP:合併/添加多維數組?
$basketA['fruit']['apple'] = 1;
$basketA['fruit']['orange'] = 2;
$basketA['fruit']['banana'] = 3;
$basketA['drink']['soda'] = 4;
$basketA['drink']['milk'] = 5;
$basketB['fruit']['apple'] = 2;
$basketB['fruit']['orange'] = 2;
$basketB['fruit']['banana'] = 2;
$basketB['drink']['soda'] = 2;
$basketB['drink']['milk'] = 2
我需要一種方式,一種方式將它們合併,所以我會得到這樣的:
$basketC['fruit']['apple'] = 3;
$basketC['fruit']['orange'] = 4;
$basketC['fruit']['banana'] = 5;
$basketC['drink']['soda'] = 6;
$basketC['drink']['milk'] = 7;
實多維數組將會更加複雜,這個只是爲了解釋我需要的東西。
謝謝!
退房array_merge_recursive – Yada 2010-01-21 22:02:33