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

Ds\Vector::rotate

(PECL ds >= 1.0.0)

Ds \ Vector :: rotate - 将向量旋转给定数量的旋转。

描述

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

向量旋转给定数量的旋转,相当于如果旋转次数为正值,或者$ vector-> unshift($ vector-> pop),如果为负数则相当于连续调用$ vector-> push($ vector-> shift()) ())。

参数

rotations

矢量旋转的次数。

返回值

没有返回值。当前实例的向量将被旋转。

例子

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

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

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

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

上面的例子会输出类似于:

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

← Ds\Vector::reversed

Ds\Vector::set →

扫码关注腾讯云开发者

领取腾讯云代金券