class Solution {
/**
* @param Integer[] $nums1
* @param Integer[] $nums2
* @return Float
*/
function findMedianSortedArrays($nums1, $nums2) {
$len1=count($nums1);
$len2=count($nums2);
$mid=intdiv($len1+$len2,2)+1;
$sortedArr=[];
while(true){
if(current($nums1)===false){
$sortedArr=array_merge($sortedArr,array_slice($nums2,key($nums2),$mid-count($sortedArr)));
break;
}
if(current($nums2)===false){
$sortedArr=array_merge($sortedArr,array_slice($nums1,key($nums1),$mid-count($sortedArr)));
break;
}
if(current($nums1)>=current($nums2)){
$sortedArr[]=current($nums2);
next($nums2);
}else{
$sortedArr[]=current($nums1);
next($nums1);
}
if(count($sortedArr)>$mid-1){
break;
}
}
if(($len1+$len2)%2){
return end($sortedArr);
}
return (end($sortedArr)+prev($sortedArr))/2;
}
}