如何合并这些数组?
$array1 = array('1' => 'Dog','2' =>'cat');
$array2 = array('1'=>'idly', '2' => 'dosa');
$array3 = array('1'=>'modi', '2'=>'rahul');
我想合并这些数组,所以我的最终输出是:
array(
'1'=>'dog',
'2'=>'cat',
'3'=>'idly',
'4'=>'dosa',
'5'=>'modi',
'6'=>'rahul'
);
这可能吗?
答案 0 :(得分:2)
如何使用 array_merge — Merge one or more arrays :
$array1 = array('1'=>'Apple', '2'=>'Banana');
$array2 = array('1'=>'Carrot', '2'=>'Dragon Fruit');
$array3 = array('1'=>'Eggplant', '2'=>'Figs');
$array4 = array_merge($array1, $array2, $array3);
print_r($array4);
输出:
Array
(
[0] => Apple
[1] => Banana
[2] => Carrot
[3] => Dragon Fruit
[4] => Eggplant
[5] => Figs
)