You are here: Home / Topics / How to merge two arrays in a new array

How to merge two arrays in a new array

Filed under: PHP on 2022-11-17 06:42:20

The below program is to merge two arrays into a new array using PHP array_merge() function. The PHP echo statement is used to output the result on the screen. An array is a single variable which can store multiple values at a time. The PHP array_merge() function is used to merge one or more arrays into a single array.
Example

<!DOCTYPE html>
<html>
<body>

<?php
$arr1 = array("London","Paris");
$arr2 = array("Switzerland","Scotland");
print_r(array_merge($arr1,$arr2));
?>

</body>
</html>
Output

Array ( [0] => London [1] => Paris [2] => Switzerland [3] => Scotland )

About Author:
D
Deepak Sahoo     View Profile
I am preparing for UPSC. My dream is to be IAS.