$mylist2 = array(1,2,3,4,5,6,7);
$mylist2[0]=$mylist2[(count($mylist2)-1)];
$my = $mylist2;
$i=0;
while ($i < count($mylist2)-1) {
$mylist2[$i+1] = $my[$i];
echo"$mylist2[$i], ";
$i++;
}
$mylist2 = array(1,2,3,4,5,6,7);
$count = count($mylist2);
$newArray = array();
foreach ( $mylist2 as $key => $value ) {
if ( ($count-1) == $key ) {
$newArray[0] = $value;
} else {
$newArray[$key+1] = $value;
}
}
ksort($newArray);
var_dump(implode(", ", $newArray));
function rotateArray($arr, $shift) {
$shift %= count($arr);
array_unshift($arr, ...array_splice($arr, -$shift));
return $arr;
}
$arr = range(1, 7);
echo implode(', ', rotateArray($arr, 1)); // 7, 1, 2, 3, 4, 5, 6
echo implode(', ', rotateArray($arr, -3)); // 4, 5, 6, 7, 1, 2, 3
echo implode(', ', rotateArray($arr, 69)); // 2, 3, 4, 5, 6, 7, 1