📜  PHP | Ds\Vector rotate()函数

📅  最后修改于: 2022-05-13 01:56:29.198000             🧑  作者: Mango

PHP | Ds\Vector rotate()函数

Ds\Vector::rotate()函数是PHP中的一个内置函数,用于将数组元素旋转给定的旋转次数。旋转也发生在原地。

句法:

void public Ds\Vector::rotate( $rotations )

参数:此函数接受单个参数$rotations保存旋转次数。

返回值:此函数不返回任何值。

下面的程序说明了PHP中的Ds\Vector::rotate()函数:

方案一:

rotate(3);
  
echo("\nVector after rotating by 3 places\n");
  
// Display the Vector elements
print_r($vect);
  
?>

输出:

Original Vector
Ds\Vector Object
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
)

Vector after rotating by 3 places
Ds\Vector Object
(
    [0] => 4
    [1] => 5
    [2] => 1
    [3] => 2
    [4] => 3
)

程序2:当旋转次数大于向量中的元素数时。

rotate(6);
  
echo("\nVector after rotating by 6 places\n");
  
// Display the Vector elements
print_r($vect);
  
?>

输出:

Original Vector
Ds\Vector Object
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
)

Vector after rotating by 6 places
Ds\Vector Object
(
    [0] => 2
    [1] => 3
    [2] => 4
    [3] => 5
    [4] => 1
)

参考: http: PHP。 PHP