(PECL ds >= 1.0.0)
Ds\Vector::rotate — 将向量旋转给定次数
将向量旋转给定次数,这等效于如果旋转次数为正,则连续调用 $vector->push($vector->shift()),如果为负,则调用 $vector->unshift($vector->pop())。
rotations向量应旋转的次数。
没有返回值。当前实例的向量将被旋转。
示例 #1 Ds\Vector::rotate() 示例
<?php
$vector = new \Ds\Vector(["a", "b", "c", "d"]);
$vector->rotate(1); // "a" 被移位,然后推入。
print_r($vector);
$vector->rotate(2); // "b" 和 "c" 都被移位,然后推入。
print_r($vector);
?>以上示例将输出类似以下内容
(
[0] => b
[1] => c
[2] => d
[3] => a
)
Ds\Vector Object
(
[0] => d
[1] => a
[2] => b
[3] => c
)