想合并
array(
2 => 'a'
3 => 'b'
);
和
array(
7 => 'c'
9 => 'd'
);
要得到
array(
2 => 'a'
3 => 'b'
7 => 'c'
9 => 'd'
);
array_merge()
给我
array(
0 => 'a'
1 => 'b'
2 => 'c'
3 => 'd'
);
很简单,你可以这样做-
$result = $array1 + $array2;
简单的例子
$array1 = array(0 => 'zero_a', 2 => 'two_a', 3 => 'three_a');
$array2 = array(1 => 'one_b', 3 => 'three_b', 4 => 'four_b');
$result = $array1 + $array2;
var_dump($result);
输出
array(5) {
[0]=>
string(6) "zero_a"
[2]=>
string(5) "two_a"
[3]=>
string(7) "three_a"
[1]=>
string(5) "one_b"
[4]=>
string(6) "four_b"
}
您可以简单地添加数组:$myArray1 + $myArray2;
使用数组统一运算符:“+”
<?php
$foo = array(
2 => 'a',
3 => 'b'
);
$bar = array(
7 => 'c',
9 => 'd'
);
$result = $foo + $bar;
print_r( $result );
$阵列1 + $阵列2;
是我的选择,而且效果很好。