array_merge与+的区别
<?php $a = array("a"=>1,"b"=>2,"c"=>3); $b = array("aa"=>1,"22"=>2,"cc"=>3); $data = array_merge($a,$b); print_r($data); $data2 = $a + $b; print_r($data2); ?>结果:
Array ( [a] => 1 [b] => 2 [c] => 3 [aa] => 1 [0] => 2 [cc] => 3 ) Array ( [a] => 1 [b] => 2 [c] => 3 [aa] => 1 [22] => 2 [cc] => 3 )
array_merge:数字键名将会被重新编号!如果你想完全保留原有数组并只想新的数组附加到后面,用
+
运算符。