Rotate Array Left

Rotate array elements to the left by a specified number of positions, wrapping elements around.

Code

General
$k = $n % count($arr);
return array_merge(array_slice($arr, $k), array_slice($arr, 0, $k));

Parameters

Array to rotate

Positions to rotate

Server

More PHP Snippets