array_mergeの履歴

忘れやすいのでメモ

array_mergeは重複キーを上書きする。
+演算子は重複キーを上書きしない。

<?php

$x = array('aaa' => 1, 'bbb' => 2, 'ccc' => 3);
$y = array('ccc' => 5, 'ddd' => 6);

print_r(array_merge($x, $y)); 
print_r($x + $y);

$x = array('a', 'b', 'c', 'd');
$y = array('b', 'c');

print_r(array_merge($x, $y));
print_r($x + $y);

Array
(
    [aaa] => 1
    [bbb] => 2
    [ccc] => 5
    [ddd] => 6
)
Array
(
    [aaa] => 1
    [bbb] => 2
    [ccc] => 3
    [ddd] => 6
)
Array
(
    [0] => a
    [1] => b
    [2] => c
    [3] => d
    [4] => b
    [5] => c
)
Array
(
    [0] => a
    [1] => b
    [2] => c
    [3] => d
)