📜  PHP | Ds\Sequence rotate()函数

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

PHP | Ds\Sequence rotate()函数

Ds\Sequence::rotate()函数是PHP中的一个内置函数,用于将序列元素旋转给定的旋转次数。

句法:

void abstract public Ds\Sequence::rotate ( int $rotations )

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

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

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

方案一:

rotate(3); 
  
echo("\nSequence after rotating by 3 places\n"); 
  
// Display the Sequence elements 
print_r($seq); 
  
?> 
输出:
Original Sequence
Ds\Vector Object
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
)

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

方案二:

rotate(8); 
  
echo("\nSequence after rotating by 8 places\n"); 
  
// Display the Sequence elements 
print_r($seq); 
  
?> 
输出:
Original Sequence
Ds\Vector Object
(
    [0] => Geeks
    [1] => for
    [2] => Geeks
    [3] => Computer
    [4] => Science
    [5] => Portal
)

Sequence after rotating by 8 places
Ds\Vector Object
(
    [0] => Geeks
    [1] => Computer
    [2] => Science
    [3] => Portal
    [4] => Geeks
    [5] => for
)

参考: https://www. PHP.net/manual/en/ds-sequence.rotate。 PHP