How can I make a cyclic shift of an array by 1 to the right, without cycles?
- @IVsevolod, and a little more detail about the problem? And that " cyclical, but without cycles " - even in the head with difficulty fit. - Deonis
- @Deonis, meaning putting the last element of the array at the beginning of the array, without using cycles. - IVsevolod
|
1 answer
Try this:
$array = array(1, 2, 3); array_unshift($array, array_pop($array)); var_dump($array); // 3, 1, 2 Not tested, but should work. array_pop removes the last element from an array and returns its value. array_unshift adds a value to the beginning of the array.
- It works, thanks. - IVsevolod
- Please :) - Artem Ryzhov
|