首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Ds\Sequence::rotate

(PECL ds >= 1.0.0)

Ds \ Sequence :: rotate - 将序列旋转给定数量次。

描述

代码语言:javascript
复制
abstract public void Ds\Sequence::rotate ( int $rotations )

将序列旋转给定数量次,相当于$sequence->push($sequence->shift())如果旋转次数为正数或$sequence->unshift($sequence->pop())负数,则相继调用。

参数

rotations

序列应该旋转的次数。

返回值

没有返回值。当前实例的顺序将被旋转。

示例

示例#1 Ds \ Sequence :: rotate()示例

代码语言:javascript
复制
<?php
$sequence = new \Ds\Vector(["a", "b", "c", "d"]);

$sequence->rotate(1);  // "a" is shifted, then pushed.
print_r($sequence);

$sequence->rotate(2);  // "b" and "c" are both shifted, the pushed.
print_r($sequence);
?>

上面的例子会输出如下信息:

代码语言:javascript
复制
(
    [0] => b
    [1] => c
    [2] => d
    [3] => a
)
Ds\Vector Object
(
    [0] => d
    [1] => a
    [2] => b
    [3] => c
)

← Ds\Sequence::reversed

Ds\Sequence::set →

扫码关注腾讯云开发者

领取腾讯云代金券