array_merge是丟棄原來的數字的key,而保留字符串形式的key,然後組成一個新的數組,不管鍵名是否一樣,都不合並,除非鍵名和value同時一樣並且還必須是字符串形式的key才合並。而array+array就是不管你是什麼情況,它都只會先把前面的數組的數據先放到新生成的數組中,之後再看第二個array是否比第一個數組個數多,多的就添加進來,它只數個數,但是這種情況它會添加進來:
$a = array('d'=>'aass','e'=>'adsdfd','asd'=>'asdsdd','ddfg'=>'dssdf');
復制代碼 代碼如下:
$b = array('d'=>'adddd','adsdfd','asdfsddddd','d'=>'aass');
$d = $a + $b;
$e = array_merge($a,$b);
var_dump($d);
var_dump($e);
打印:
array
'd' => string 'aass' (length=4)
'e' => string 'adsdfd' (length=6)
'asd' => string 'asdsdd' (length=6)
'ddfg' => string 'dssdf' (length=5)
0 => string 'adsdfd' (length=6)
1 => string 'asdfsddddd' (length=10)
array
'd' => string 'aass' (length=4)
'e' => string 'adsdfd' (length=6)
'asd' => string 'asdsdd' (length=6)
'ddfg' => string 'dssdf' (length=5)
0 => string 'adsdfd' (length=6)
1 => string 'asdfsddddd' (length=10)