3v4l.org

run code in 200+ PHP versions simultaneously
<?php function BinSearch($needle, $haystack){ (int) $m = ceil(count($haystack) / 2); $midpoint = $haystack[$m]; $lower_half = array_slice($haystack, 0, $m); $upper_half = array_slice($haystack, -$m, count($haystack)); if ($needle == $midpoint){ return $haystack[$needle]; } else if ($needle < $midpoint) { return BinSearch($needle, $lower_half); } else if ($needle > $midpoint) { return BinSearch($needle, $upper_half); } } $x = range(0,9999); BinSearch(8273,$x);
Output for 7.1.25 - 7.3.5
Notice: Undefined offset: 8273 in /in/WNd1u on line 11