3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $A = [1, -2, 5, -9, 9]; $X = -2; $s = solution($A, $X); var_dump($s, array_search($X, $A)); function solution($A, $X) { sort($A); $N = sizeof($A); if ($N == 0) { return -1; } $l = 0; $r = $N - 1; while ($l < $r && $X !== $A[$l] ) { $m = (int)(($l + $r) / 2); if ($A[$m] > $X) { $r = $m - 1; } else { $l = $m; } } if ($A[$l] == $X) { return $l; } else return -1; }
Output for 5.4.0 - 5.4.22

Process exited with code 137.
Output for 5.2.15 - 5.3.27
Parse error: syntax error, unexpected '[' in /in/Mke2s on line 3
Process exited with code 255.