PHP: 'rotate' an array?

后端 未结 14 1975
小鲜肉
小鲜肉 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:07

    No. Check the documentation for array_shift and its related functions for some tools you can use to write one. There might even be an array_rotate function implemented in the comments of that page.

    It's also worth reading through the array functions listed on the left-hand sidebar to get a full understanding of what array functions are available in PHP.

提交回复
热议问题