Loading... # PHP array_merge() vs array + array ## array_merge * key -> string: key 相同,後面覆蓋前面 * key -> number: key 相同,後面覆蓋前面,然後所有 key 重新排列(從 0 開始) ``` $arrA = ['a' => 1, 'b' => 2, 1 => 3]; $arrB = ['b' => 1, 1 => 4, 5]; var_export(array_merge($arrA, $arrB)); ## output array ('a' => 1,'b' => 1, 0 => 3,1 => 4,2 => 5) ``` ## array + array * key -> string: key 相同,前面會覆蓋後面 * key -> number: key 相同,前面會覆蓋後面並 key 不會重新排列 ``` $arrA = ['a' => 1, 'b' => 2, 1 => 3]; $arrB = ['b' => 1, 1 => 4, 5]; var_export($arrA + $arrB); ## output array ('a' => 1, 'b' => 2,1 => 3,2 => 5) ``` © Reprint prohibited Support Appreciate the author AliPayWeChat Like If you think my article is useful to you, please feel free to appreciate