What is the purpose of the php array_merge function?
The purpose of the PHP array_merge function is to combine one or more arrays into a new array. It takes multiple arrays as parameters and returns a new array containing all the elements from the input arrays. If the input arrays have the same key names, the values from the later arrays will overwrite the values from the earlier arrays.
For example:
$array1 = array('a', 'b', 'c');
$array2 = array(1, 2, 3);
$result = array_merge($array1, $array2);
print_r($result);
Output:
Array
(
[0] => a
[1] => b
[2] => c
[3] => 1
[4] => 2
[5] => 3
)
In the example above, array_merge combines $array1 and $array2 into a new array $result, which includes all elements from $array1 and $array2.