<?php
$arr = [7,10,15, 23, 25,40,55,78,98];
$search_element = 1;
$end = count($arr) -1;//6
$start = 0;
//If mid > element, traverse left OR mid < element, traverse right
$found = 0;
//echo count($arr)." ".$start;
while($end >= $start){
$mid = (int)($start + ($end - $start)/2);
if($arr[$mid] == $search_element){
$found = 1;break;
}elseif($arr[$mid] > $search_element){
$end = $mid -1;
}elseif($arr[$mid] < $search_element){
$start = $mid +1;
}
}
echo($found);
To embed this project on your website, copy the following code and paste it into your website's HTML: