Rotate Array Right

Rotate array elements to the right 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