Home > Article > Backend Development > php-Arrays function-array_merge-merge one or more arrays_PHP tutorial
array_merge() merges one or more arrays
【Function】
This function combines the elements of one or more arrays. The values in one array are appended to the previous array.
Return the array as the result. If the input arrays have the same string key names, these values will be overwritten to the previous
Value. However, if the array contains the same numeric key name, the latter value will not overwrite the original value, and
is appended to the back. If only an array is given, and the array is numerically indexed, the key names will be re-indexed in a consecutive manner
【Scope of use】
php4, php5.
【Use】
array array_merge( array array1[,array array2[,array...]] )
arrayn/required/array to be used for merging
【Example】
[php]
$arr1 = array("color"=>array("favorite"=>"red"),5);
$arr2 = array(10,"color"=>array("favorite"=>"green","blue"));
var_dump(array_merge($arr1));
/*
array(2) {
["color"]=>
array(1) {
["favorite"]=>
String(3) "red"
}
[0]=>
int(5)
}
*/
Excerpted from zuodefeng’s notes