PHP Cyclic Rotation
function cyclicRotation(array $a, int $k): array
{
if ( ! empty($a)) {
for ($i = 0; $i < $k; $i++) {
array_unshift($a, array_pop($a));
}
}
return $a;
}
This rotates the array to the right by K steps and keeps the wrap-around values in the correct order.