Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function moveNElementsToTheEnd ($initArray, $n)
- {
- if ($n > 0) {
- $initArray[] = array_shift($initArray);
- return moveNElementsToTheEnd($initArray, $n-1);
- }
- return $initArray;
- }
- /*
- 1..10, n=3
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- 2, 3, 4, 5, 6, 7, 8, 9, 10, 1
- 3, 4, 5, 6, 7, 8, 9, 10, 1, 2
- 4, 5, 6, 7, 8, 9, 10, 1, 2, 3
- 1..13, n=3
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
- 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1
- 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1, 2
- 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1, 2, 3
- */
Advertisement
Add Comment
Please, Sign In to add comment