如何将3个或更多阵列合并为一个阵列?

时间:2019-05-23 16:49:16

标签: php array-merge

如何合并这些数组?

$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'
);

这可能吗?

1 个答案:

答案 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
)