Definition:
The array_merge()
function merge one or more arrays into one array.
This function merges the elements of one or more arrays together in such a way that the values of one are appended to the end of the previous one. It returns a new array with merged elements.
The basic syntax of the array_merge()
function is given with:
array_merge(array1, array2, ...)
The array_merge()
function accepts the following parameters.
Parameter | Description |
---|---|
array1 | Optional. Specifies the first array to merge. |
array2 | Optional. Specifies the second array to merge. |
... | Optional. Specifies more arrays to merge. |
Lets understand with Example :
The following example shows the array_merge()
function in action.
Output :
Array
(
[0] => Web
[1] => Designing
[2] => House
[3] => Online
[4] => Promotion
)
Example2 : Merge two associative arrays into one array
Note: If two or more array elements have the same key, the last one overrides the others.
Output :
Array
(
[a] => web
[b] => designing
[c] => house
)