How to use the php array_merge function?

The array_merge function is used to combine one or more arrays. It returns a new array that contains all the values from the input arrays.

Here is how to use it:

<?php
// 定义两个数组
$array1 = array('a', 'b', 'c');
$array2 = array(1, 2, 3);

// 使用array_merge合并数组
$result = array_merge($array1, $array2);

// 打印合并后的结果
print_r($result);
?>

Running the above code, the output will be:

Array
(
    [0] => a
    [1] => b
    [2] => c
    [3] => 1
    [4] => 2
    [5] => 3
)

Note: If there are duplicate keys in two arrays, the key in the latter array will override the key in the former array, but the value will not be overwritten.

bannerAds