![](/style/images/good.png)
![](/style/images/bad.png)
How to merge two or more arrays into one array in PHP
source link: https://www.laravelcode.com/post/how-to-merge-two-or-more-arrays-into-one-array-in-php
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to merge two or more arrays into one array in 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:
<?php
$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);
print_r($result);
?>
![Harsukh Makwana](https://www.laravelcode.com/upload/author.jpg)
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]
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK