How can foreach and array_map functions be utilized to merge arrays effectively in PHP?

When merging arrays in PHP, the foreach function can be used to iterate over each element in an array and add it to a new merged array. On the other hand, the array_map function can be utilized to apply a callback function to each element of one or more arrays and merge them together. By using these functions effectively, arrays can be merged in a concise and efficient manner.

// Using foreach to merge arrays
$array1 = [1, 2, 3];
$array2 = [4, 5, 6];
$mergedArray = [];

foreach ($array1 as $element) {
    $mergedArray[] = $element;
}

foreach ($array2 as $element) {
    $mergedArray[] = $element;
}

print_r($mergedArray);

// Using array_map to merge arrays
$array1 = [1, 2, 3];
$array2 = [4, 5, 6];

$mergedArray = array_map(null, $array1, $array2);
print_r($mergedArray);