<?php
date_default_timezone_set('Asia/Shanghai');
function binarySearch($array,$target){
$start = 0;
$end = count($array)-1;
while ($start<=$end){
$mid=$start + ($end - $start)/2;
if($array[$mid]==$target){
return intval($mid);
}elseif ($array[$mid]<$target){
$start = $mid+1;
}else{
$end = $mid-1;
}
}
return -1;
}
$tmpArray = [];
$start = microtime(true);
for ($i=0;$i<1000;$i++){
$tmpArray[$i] = $i;
}
$resArr = binarySearch($tmpArray,153);
var_dump($resArr);
$end = microtime(true);
var_dump((($end-$start)*1000).'ms');