Merge two arrays in PHP

PHP array_merge() Function

Merges two arrays into one array:

Example :

Description
The array_merge() function merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array.

If the arrays have the same string keys then the later value of that key would override the previous one. If the arrays contains the numeric keys, the later value will not override the original value, but will be appended.

Array values with numeric keys will be renumbered with incrementing keys starting from zero in the result array.

Example :
1. Array with numeric key

2. If arrays has the same keys

Merge two arrays in php is common requirement and array_merge() is the handy function for this purpose

You Might Interested In