PHP array_merge() Function

0

The array_merge() function merges one or more arrays into one array.

If the input arrays have matching string keys, then the later value will override it’s the previous counterpart. If the input arrays contain numeric keys, the later value will be appended instead of overriding the original value. If there is only one array, the array is numerically indexed, the keys get reindexed in a continuous way.

Parameter Description
array1 Required. Specifies an array
array2 Optional. Specifies an array
array3,… Optional. Specifies an array

Syntax

 array_merge(array1,array2,array3...) 

Example

$array1=array("a"=>"Cooper","b"=>"Samuel");
$array2=array("c"=>"Alex","b"=>"Prince");
print_r(array_merge($array1,$array2));

Output

Array ( [a] => Cooper [b] => Prince [c] => Alex )