3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $A = [-9, -2, 1, 5, 9]; function solution(&$A, $X) { $N = sizeof($A); if ($N == 0) { return -1; } $l = 0; $r = $N - 1; while ($l < $r ) { $m = (int)(($l + $r) / 2); if ($A[$m] === $X) return $m; if ($A[$m] > $X) { $r = $m; } else { $l = $m; } } if ($A[$l] == $X) { return $l; } else return -1; } var_dump(solution($A, -9)); var_dump(solution($A, -2)); var_dump(solution($A, 5)); var_dump(solution($A, 42));
Output for 5.4.0 - 5.4.22
int(0) int(1) int(3)
Process exited with code 137.
Output for 5.2.15 - 5.3.27
Parse error: syntax error, unexpected '[' in /in/Dl4U1 on line 3
Process exited with code 255.