我们先看下DEMO

总结

+号

(键名相同,不追加)

  1. 不覆盖,只是追加不存在的键名和对应的值
  2. 键名不重新索引
  3. 无论是全部数字键名还是混合,都只是追加键名和值,如果键名相同则不进行追加,即把最先出现的值作为最终结果返回

array_merge

合并

array_merge_recursive

递规合并,它和ARRAY_MERGE不同的是,如果KEY值相加,但VALUE不同,不会覆盖,会组成新的数组元素,并不会覆盖

DEMO

$fruit1 = array("apple" => "red", "banana" => "yellow");
$fruit2 = array("pear" => "yellow", "apple" => "green");
show(array_merge($fruit1, $fruit2));
show(array_merge_recursive($fruit1, $fruit2));
show($fruit1+$fruit2);

    ##输出
##array_merge
Array
(
    [apple] => green
    [banana] => yellow
    [pear] => yellow
)
##array_merge_recursive
Array
(
    [apple] => Array
        (
            [0] => red
            [1] => green
        )

    [banana] => yellow
    [pear] => yellow
)
##+号
Array
(
    [apple] => red
    [banana] => yellow
    [pear] => yellow
)