Bring it one! 😃
Binary Search
<?php
function binary_search($array, $value, $left, $right) {
if($right<$left)
return false;
$mid = floor(($left+$right)/2);
if($array[$mid] == $value)
return true;
elseif $value < $array[$mid]
return binary_search($array, $value, $left, $mid-1);
else
return binary_search($array, $value, $mid+1, $right);
}
$members = array("Allison",
"David",
"Brian",
"Eric",
"Ben",
"Mark",
"Mike");
if(binary_search($members, $name, 0, count($members)))
$error=false;
} else {
$error=true;
}
?>
Just a joke really, I would have thought that the initial overhead would outway any possible gain. It's good fun though 😃