3v4l.org

run code in 300+ PHP versions simultaneously
<?php function popUnshift(array $indexedArray, int $popShiftsCount): array { $count = count($indexedArray); if ($count < 2) { return $indexedArray; } $remainder = $popShiftsCount % $count; if (!$remainder) { return $indexedArray; } return array_merge( array_splice($indexedArray, -$remainder), $indexedArray ); } $A = [1, 2, 3, 4]; foreach (range(0, 9) as $K) { var_export(popUnshift($A, $K)); echo "\n---\n"; }

preferences:
52.89 ms | 402 KiB | 5 Q