gistfile1.txt $rightIndex){ echo "找不到了"; return; } $middleIndex=round(($leftIndex+$rightIndex)/2); //如果大于,像后面找 if($final$arr[$middleIndex]){ search($arr,$final,$middleIndex+1,$rightIndex); //如果小于,应该向前
$rightIndex){ echo "找不到了"; return; } $middleIndex=round(($leftIndex+$rightIndex)/2); //如果大于,像后面找 if($final>$arr[$middleIndex]){ search($arr,$final,$middleIndex+1,$rightIndex); //如果小于,应该向前面找 }else if($final<$arr[$middleIndex]){ search($arr,$final,$leftIndex,$middleIndex-1); }else{ echo "找到了下标是$middleIndex"; } } $arr=array(10,88,99,888,7777); search($arr,99,0,count($arr)-1); ?>