3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $c = [1,2,4,8,18,20,33,66,99]; function indexOfNumb(array $base, $x) { $leftI = 0; $rightI = count($base) - 1; do { $centerI = floor(($rightI + $leftI) / 2); if($base[$centerI] === $x) { return $centerI; } elseif($base[$centerI] > $x && $centerI !== $rightI) { $rightI = $centerI; } elseif($base[$centerI] < $x && $centerI !== $leftI) { $leftI = $centerI; } else { return ($x - $base[$leftI] > $base[$rightI] - $x) ? $rightI : $leftI; } } while(1); } var_dump(indexOfNumb($c, 65));
based on cABIB
Output for 5.4.9 - 7.3.0beta1
float(7)
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/sULBB on line 3
Process exited with code 255.