$arr = array('a','b','c','d','e','f','g');
$i = 3;
$arr2 = array_merge(array_slice($arr, $i), array_slice($arr, 0, $i));
var_dump($arr2);
Another solution:
$arr = array('a','b','c','d','e','f','g');
$arr2 = array();
$shift = 3;
for ($i = $shift; $i < count($arr); $i++) {
$arr2[] = $arr[$i];
}
for ($i = 0; $i < $shift; $i++) {
$arr2[] = $arr[$i];
}
var_dump($arr2);
Solution without temporary array:
$arr = array('a','b','c','d','e','f','g');
for ($j = 0; $j < 3; $j++) {
$first_letter = $arr[0];
for ($i = 1; $i < count($arr); $i++) {
$arr[$i - 1] = $arr[$i];
}
$arr[count($arr) - 1] = $first_letter;
}
var_dump($arr);