What's the difference between array_merge and array + array?

后端 未结 9 1643
遥遥无期
遥遥无期 2020-11-29 21:26

A fairly simple question. What\'s the difference between:

$merged = array_merge($array1, $array2);

and

$merged = $array1 +          


        
9条回答
  •  迷失自我
    2020-11-29 22:03

    The difference is:

    The + operator takes the union of the two arrays, whereas the array_merge function takes the union BUT the duplicate keys are overwritten.

提交回复
热议问题