English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The PHP array_merge() function merges one or more arrays into one array.
array array_merge( array $array1 , array $array2 , array $array3...]]);
The array_merge() function merges one or more arrays by combining their elements, appending the values of one array to the end of the previous array. Returns the resulting array.
If there are duplicate string key names in the input arrays, the value after the key name will overwrite the previous value. However, if the array contains numeric key names, the value after will not overwrite the original value, but will be appended to the end.
If only one array is given and the array is numeric indexed, the keys will be reindexed continuously.
Serial Number | Parameters and Description |
---|---|
1 | array1(Required) It specifies an array. |
2 | array2(Optional) It specifies an array. |
3 | array3(Optional) It specifies an array. |
It returns the resulting array.
The following example explains how to merge two arrays into one array
<?php $input = array("a"=>"Horse","b"=>"Cat","c"=>"Dog"); $input1 = array("d"=>"Cow","a"=>"Cat","e"=>"elephant"); print_r(array_merge($input,$input1)); ?>Test and See‹/›
Output Result:
Array ( [a] => Cat [b] => Cat [c] => Dog [d] => Cow [e] => elephant )