3v4l.org

run code in 300+ PHP versions simultaneously
<?php $x = [1,2,3,4,5]; $y = [2,3,4,5,7]; $z = [10,11,12,13,14]; $f = [2,3,4,5,14]; function check(array $x) { sort($x); $isStraight = true; $lastNum = $x[0]; for ($a = 1; $a < 5; $a ++) { if (($lastNum +1) != $x[$a]) { $isStraight = false; } $lastNum = $x[$a]; } if (!$isStraight && $x[0] == 2 && $x[4] == 14) { $x[4] = 1; $isStraight = check($x); } return $isStraight; } var_dump(check($x)); var_dump(check($y)); var_dump(check($z)); var_dump(check($f));
Output for 7.1.25 - 7.1.28, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
bool(true) bool(false) bool(true) bool(true)

preferences:
167.37 ms | 403 KiB | 162 Q