3v4l.org

run code in 300+ PHP versions simultaneously
<?php // This code is public domain. The original author is Marc Ermshaus. error_reporting(-1); /** * Circularly shifts an array * * Shifts to right for $steps > 0. Shifts to left for $steps < 0. Keys are * preserved. * * @param array $array Array to shift * @param int $steps Steps to shift array by * @return array Resulting array */ function array_circular(array $array, $steps = 1) { if ($steps === 0) { return $array; } $l = count($array); if ($l === 0) { return $array; } $steps = $steps % $l; $steps *= -1; return array_merge(array_slice($array, $steps), array_slice($array, 0, $steps)); } header('content-type: text/plain'); $a = array("1" => "Primeiro", "2"=>"Segundo", "3"=>"Terceiro", "4"=> "Quarto"); $l = count($a); for ($i = $l * -2; $i <= $l * 2; $i++) { printf("% 3s : %s\n", $i, implode(', ', array_shift_circular($a, $i))); } ?>
Output for 7.1.0 - 7.1.33, 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.17, 8.3.0 - 8.3.4
Fatal error: Uncaught Error: Call to undefined function array_shift_circular() in /in/sSCo7:44 Stack trace: #0 {main} thrown in /in/sSCo7 on line 44
Process exited with code 255.

preferences:
176.13 ms | 403 KiB | 198 Q