3v4l.org

run code in 300+ 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 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: Undefined array key 8273 in /in/WNd1u on line 11
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined offset: 8273 in /in/WNd1u on line 11
Output for 7.3.32 - 7.3.33

preferences:
157.19 ms | 401 KiB | 184 Q