3v4l.org

run code in 300+ PHP versions simultaneously
<?php function BinSearch($needle, $haystack){ $midpoint = count($haystack) / 2; $lower_half = array_slice($haystack, 0, $midpoint); $upper_half = array_slice($haystack, -$midpoint, count($haystack)); if($needle < $midpoint){ BinSearch($needle, $lower_half); } else if($needle > $midpoint){ BinSearch($needle, $upper_half); } if(count($haystack == 1)){ return true;} else if(count($haystack) == 0) { return false;} } $x = range(0,999); BinSearch(82,$x);

preferences:
57.92 ms | 402 KiB | 5 Q