<?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:是第二个数组覆盖第一个数组键名相同。数字索引会被保留(+会被直接覆盖掉),而且数字索引被重新排序。