<?php
$d1=array(
'2015-6-1'=>'0',
'2015-6-2'=>'0',
'2015-6-3'=>'0',
'2015-6-4'=>'0',
'2015-6-5'=>'100',
'2015-6-6'=>'0',
'2015-6-7'=>'end',
'theend'=>'end!',
'1'=>'the one',
'21'=>'the three'
);
$d2=array(
'2015-6-1'=>'9',
'2015-6-2'=>'8',
'2015-6-3'=>'7',
'2015-6-4'=>'6',
'2015-6-5'=>'5',
'2015-6-6'=>'4',
'1'=>'the two'
);
var_dump($d1+$d2);
var_dump(array_merge($d1,$d2));
// var_dump($days);
result:
array(10) {
["2015-6-1"]=>
string(1) "0"
["2015-6-2"]=>
string(1) "0"
["2015-6-3"]=>
string(1) "0"
["2015-6-4"]=>
string(1) "0"
["2015-6-5"]=>
string(3) "100"
["2015-6-6"]=>
string(1) "0"
["2015-6-7"]=>
string(3) "end"
["theend"]=>
string(4) "end!"
[1]=>
string(7) "the one"
[21]=>
string(9) "the three"
}
array(11) {
["2015-6-1"]=>
string(1) "9"
["2015-6-2"]=>
string(1) "8"
["2015-6-3"]=>
string(1) "7"
["2015-6-4"]=>
string(1) "6"
["2015-6-5"]=>
string(1) "5"
["2015-6-6"]=>
string(1) "4"
["2015-6-7"]=>
string(3) "end"
["theend"]=>
string(4) "end!"
[0]=>
string(7) "the one"
[1]=>
string(9) "the three"
[2]=>
string(7) "the two"
}
[Finished in 0.9s]
1、兩個數組相加:(+):是用第一個數組覆蓋第二個數組中鍵名字相同的。數字索引和字符串索引(關聯數組)都會被覆蓋,而且數字索引下標保留。
2、array_merge:是第二個數組覆蓋第一個數組鍵名相同。數字索引會被保留(+會被直接覆蓋掉),而且數字索引被重新排序。