PHP is an open source scripting language that is welcomed and used by programmers around the world. PHP is very powerful and provides many practical functions when processing arrays, such as the array_merge() function.
The array_merge() function can merge one or more arrays into one array. Let's take a look at the usage and precautions of this function.
Syntax:
array_merge ( array $array1 [, array $... ] ) : array
Parameters:
Return value:
Example 1:
$array1 = array('a'=>1,'b'=>2,'c'=>3); $array2 = array('d'=>4,'e'=>5,'f'=>6); $result_array = array_merge($array1,$array2); print_r($result_array);
Output:
Array ( [a] => 1 [b] => 2 [c] => 3 [d] => 4 [e] => 5 [f] => 6 )
Example 2:
$array1 = array('a'=>1,'b'=>2,'c'=>3); $array2 = array('d'=>4,'e'=>5,'f'=>6); $array3 = array('g'=>7,'h'=>8,'i'=>9); $result_array = array_merge($array1,$array2,$array3); print_r($result_array);
Output:
Array ( [a] => 1 [b] => 2 [c] => 3 [d] => 4 [e] => 5 [f] => 6 [g] => 7 [h] => 8 [i] => 9 )
Notes:
Summary:
The array_merge() function is a very practical function in PHP array operations. It has a wide range of uses and can easily merge multiple arrays into one array. However, when using this function, you need to pay attention to the above points to avoid errors.
The above is the detailed content of Preliminary PHP function: array_merge(). For more information, please follow other related articles on the PHP Chinese website!