Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function binarySearch($arr, $item) {
- $low = 0;
- $hight = count($arr) - 1;
- while ($low <= $hight) {
- $mid = $low + $hight;
- $guess = $arr[$mid];
- if ($guess == $item) {
- return $mid;
- } elseif ($guess > $item) {
- $hight = $mid - 1;
- } elseif ($guess < $item) {
- $low = $mid + 1;
- }
- }
- }
Add Comment
Please, Sign In to add comment