3v4l.org

run code in 300+ PHP versions simultaneously
<?php function sample(int $val, int $min, int $max) { $listLength = $max - $min + 1; $key = (($val % $listLength)) % $listLength; if ($key < 0) { $key = $listLength + ($key % $listLength); } return $min + $key; } // ?????? foreach (range(-10, 5) as $i) echo $i .'='. sample($i, 2, 5) . PHP_EOL;

preferences:
63.97 ms | 402 KiB | 5 Q