php +与array_merge的区别
-
$a = array('a', 'b');
$b = array('c', 'b');
$c = $a + $b;
print_r($c);
print_r(array_merge($a, $b));
-
$a = array(0 => 'a', 1 => 'b');
$b = array(0 => 'c', 1 => 'b');
$c = $a + $b;
print_r($c);
print_r(array_merge($a, $b));
-
$a = array('a', 'b');
$b = array('0' => 'c', 1 => 'b');
$c = $a + $b;
print_r($c);
print_r(array_merge($a, $b));
-
$a = array(0 => 'a', 1 => 'b');
$b = array('0' => 'c', '2' => 'b');
$c = $a + $b;
print_r($c);
print_r(array_merge($a, $b));
-
Array ( [0] => a [1] => b ) Array ( [0] => a [1] => b [2] => c [3] => b )
-
Array ( [0] => a [1] => b ) Array ( [0] => a [1] => b [2] => c [3] => b )
-
Array ( [0] => a [1] => b ) Array ( [0] => a [1] => b [2] => c [3] => b )
-
Array ( [0] => a [1] => b [2] => b ) Array ( [0] => a [1] => b [2] => c [3] => b )
结论:+键值合并,merge值累加