3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = range(0,1000); function closest($arr, $x) { $result = "default"; sort($arr); foreach($arr as $value) { if($value < $x) { $result = $value; } else break; } return $result; } echo closest($arr,17)."\n"; echo closest($arr,20)."\n"; echo closest($arr,6);

preferences:
28.55 ms | 405 KiB | 5 Q