How to merge two or more arrays into one array in PHP

  1529 views   2 years ago PHP

Use the PHP array_merge() function

You can use the PHP array_merge() function to merge the elements or values of two or more arrays together into a single array. The merging is occurring in such a way that the values of one array are appended to the end of the previous array. Let's check out an example:

$array1 = array(1, "fruit" => "banana", 2, "monkey", 3);
$array2 = array("a", "b", "fruit" => "apple", "city" => "paris", 4, "c");
// Merging arrays together
$result = array_merge($array1, $array2);


Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]