1 $arr=array(33,2,54,25,65,34,67,42,87,90,243,213,365,78,67,345,678); 2 sort($arr);//二分查找,一定要在一个有序的里面查找 3 sortAll($arr,54); 4 function sortAll($arr,$key,$low='0',$high='0'){ 5 if($high==0){ 6 $high=count($arr); 7 } 8 $mid=intval(($low+$high)/2); 9 if($arr[$mid]==$key){10 echo $arr[$mid].'====='.$mid;11 }else if($arr[$mid]<$key){12 sortAll($arr,$key,$mid,$high);//递归实现13 }else if($arr[$mid]>$key){14 sortAll($arr,$key,$low,$mid);//递归实现15 }else{16 echo 'sorry,not found!';17 }18 }