想要合并
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'
);
答案 0 :(得分:6)
$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"
}
答案 1 :(得分:0)
您只需添加数组:$myArray1 + $myArray2;
答案 2 :(得分:0)
使用数组协调运算符:“+”
<?php
$foo = array(
2 => 'a',
3 => 'b'
);
$bar = array(
7 => 'c',
9 => 'd'
);
$result = $foo + $bar;
print_r( $result );
答案 3 :(得分:0)
$ array1 + $ array2;
是我的选择,效果很好。