How to Merge Arrays into a Single Array in PHP?

This tutorial explains how to merge arrays into a single array in PHP. There is a predefined function array_merge(), which is used to merge arrays into one array.

Here is the Syntax of array_merge() Function:


Here array_variable1 is the first array varable name,array_variable2 is the second array variable name, array_variable3 is the third array variable name.

Example to Merge Arrays into a Single Array in PHP

The below example demonstrates how to merge two arrays into one array in PHP.




Array ( [name] => john [address] => kolkata [salary] => 90000 [name1] => sebastin [address1] => kolkata [salary1] => 900000 )

Here the first array $a is containing three elements and second array $b is containing three elements. There is a third array $c.

The function array_merge(), which is helping us to append the array elements of the second array to end the first array and then the merged array is assigning to $c. Finally, print_r() is printing the merged array.


Leave a Comment