PHP array_merge()Function
Complete PHP Array Reference Manual
Examples
Merge two arrays into one array:
Run Example »
Definition and Usage
The array_merge() function is used to merge one or more arrays into one array.
Tip:You can input one or more arrays into the function.
Note:If two or more array elements have the same key name, the last element will overwrite the other elements.
Note:If you only input one array to the array_merge() function, and the key names are integers, the function will return a new array with integer key names, re-indexed starting from 0 (see Example 1 below).
Tip:This function differs fromarray_merge_recursive()The difference between the functions is in handling the case where two or more array elements have the same key name. array_merge_recursive() does not overwrite key names, but instead recursively combines the values of multiple identical key names into one array.
Syntax
| Parameter | Description |
|---|---|
| array1 | Required. Specifies an array. |
| array2 | Optional. Specifies an array. |
| array3 | Optional. Specifies an array. |
Technical Details
| Return value: | Returns the merged array. |
|---|---|
| PHP Version: | 4+ |
| Changelog: | As of PHP 5.0, this function only accepts parameters of the array type. |
More Examples
Example 1
Only use one parameter with integer key names:
Run Example »
Complete PHP Array Reference Manual Other Extensions