Merge Two Sorted Arrays: Write a PHP function to merge two sorted arrays into a single sorted array.

function mergeSortedArrays($arr1, $arr2) {
    return array_merge($arr1, $arr2);
}

// Example usage:
$array1 = [1, 3, 5];
$array2 = [2, 4, 6];
$result = mergeSortedArrays($array1, $array2);
sort($result); // Sorting the merged array
print_r($result);

Related Posts

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Artificial Intelligence