two pointer merge for two sorted arrays
while ( $ l_curr + $ r_curr < $ l_c + $ r_c ) { if ( $ r_curr == $ r_c || ( $ l_curr != $ l_c && $ l_arr [ $ l_curr ] < $ r_arr [ $ r_curr ] ) ) { $ output [ $ in ] = $ l_arr [ $ l_curr ] ; $ l_curr ++ ; $ in ++ ; } else { $ output [ $ in ] = $ r_arr [ $ r_curr ] ; $ r_curr ++ ; $ in ++ ; } } }