Create a new array from 2 arrys in php

In PHP, you can create a new array by combining two existing arrays using the array_merge() function. Here's an example:

$array1 = array('a', 'b', 'c');
$array2 = array('d', 'e', 'f');

$newArray = array_merge($array1, $array2);

print_r($newArray);

Output:

Array
(
    [0] => a
    [1] => b
    [2] => c
    [3] => d
    [4] => e
    [5] => f
)

The array_merge() function takes two or more arrays as arguments and returns a new array that contains all the elements from the original arrays.

Alternatively, you can use the + operator to merge two arrays. This method is less common, but it can be useful in certain situations:

$array1 = array('a', 'b', 'c');
$array2 = array('d', 'e', 'f');

$newArray = $array1 + $array2;

print_r($newArray);

Output:

Array
(
    [a] => a
    [b] => b
    [c] => c
    [d] => d
    [e] => e
    [f] => f
)

Note that when using the + operator, the resulting array will have the keys from the first array, and the values from the second array. If there are duplicate keys, the values from the second array will overwrite the values from the first array.

You can also use the array_merge_recursive() function to merge two arrays recursively, which means that if the arrays have nested arrays, they will be merged recursively:

$array1 = array('a', 'b', array('c', 'd'));
$array2 = array('e', 'f', array('g', 'h'));

$newArray = array_merge_recursive($array1, $array2);

print_r($newArray);

Output:

Array
(
    [0] => a
    [1] => b
    [2] => Array
        (
            [0] => c
            [1] => d
        )

    [3] => e
    [4] => f
    [5] => Array
        (
            [0] => g
            [1] => h
        )

)