3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php private function nearest(array $arr, $needle) { $closest = current($arr); foreach ($arr as $val) { if ($val === $needle) { return $val; // found it :) } if ($val > $closest && $val < $needle) { // we found something closer and less than the needle, so use it $closest = $val; } } // we've reached the end, so return the closest solution return $closest; } $array = array(2012, 2013, 2015, 2016, 2018); $needle = "1970"; print nearest($array, $needle);
Output for 5.4.0 - 5.4.26
Parse error: syntax error, unexpected 'private' (T_PRIVATE) in /in/MWHRA on line 2
Process exited with code 255.
Output for 5.1.0 - 5.3.28
Parse error: syntax error, unexpected T_PRIVATE in /in/MWHRA on line 2
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_PRIVATE in /in/MWHRA on line 2
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_FUNCTION in /in/MWHRA on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_FUNCTION in /in/MWHRA on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/MWHRA on line 2
Process exited with code 255.