<?php
$arr1 = [2,2,3,4,7];
$arr2 = [-1,1,2,8,10];
$merged_arr = [];
$i = 0; $j = 0;
$count_arr1 = count($arr1);
$count_arr2 = count($arr2);
$total_elements = $count_arr1 + $count_arr2;
for($tcount = 0; $tcount < $total_elements; $tcount++){
if($i >= $count_arr1){
array_push($merged_arr, $arr2[$j]);
$j++;
}else if($j >= $count_arr2){
array_push($merged_arr, $arr1[$i]);
$i++;
}else if($arr1[$i] >= $arr2[$j]){
array_push($merged_arr, $arr2[$j]);
$j++;
}else{
array_push($merged_arr, $arr1[$i]);
$i++;
}
}
print'<pre>';print_r($merged_arr);
To embed this project on your website, copy the following code and paste it into your website's HTML: