PHP array_merge() Function

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.

ParameterDescription
array1Required. Specifies an array
array2Optional. 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 ) 

Leave a Reply

Your email address will not be published. Required fields are marked *