How to merge two arrays in PHP?

To merge two arrays in PHP, you can use the array_merge() function. Here's an example:

$array1 = [1, 2, 3]; $array2 = [4, 5, 6]; $mergedArray = array_merge($array1, $array2); print_r($mergedArray);

Output:

Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 )

The array_merge() function takes multiple arrays as arguments and returns a new array that contains all the elements from the input arrays. It appends the elements of the second array to the first array.