相同数组键名为数字时
- + 会保留最先出现的那个值
- array_merge 会附加到后面
$a = [1,2,3];
$b = [11,22,33];
print_r($a+$b);
print_r(array_merge($a,$b));
//输出结果为
Array
(
[0] => 1
[1] => 2
[2] => 3
)
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 11
[4] => 22
[5] => 33
)
相同数组键名为字符时
- + 会保留最先出现的那个值
- array_merge 会覆盖掉前面相同键名的值
$a = ['a'=>1,'b'=>2,'c'=>3];
$b = ['a'=>11,'b'=>22,'c'=>33];
print_r($a+$b);
print_r(array_merge($a,$b));
//输出结果为
Array
(
[a] => 1
[b] => 2
[c] => 3
)
Array
(
[a] => 11
[b] => 22
[c] => 33
)