PHP: 'rotate' an array?

后端 未结 14 1663
小鲜肉
小鲜肉 2020-11-28 14:16

is it possible to easily \'rotate\' an array in PHP ?

Like this: 1, 2, 3, 4 -> 2, 3 ,4 ,1

Is there some kind of built-in PHP function for this?

相关标签:
14条回答
  • 2020-11-28 15:08

    Please use the build in function array_reverse. It is the fastest way to 'rotate' a array in php.

    http://php.net/manual/de/function.array-reverse.php

    0 讨论(0)
  • 2020-11-28 15:09
      $numbers = array(1,2,3,4);
      array_push($numbers, array_shift($numbers));
      print_r($numbers);
    

    Output

    Array
    (
        [0] => 2
        [1] => 3
        [2] => 4
        [3] => 1
    )
    
    0 讨论(0)
提交回复
热议问题