📜  PHP | Ds\Deque rotate()函数

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

PHP | Ds\Deque rotate()函数

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

句法:

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

参数:此函数接受单个参数$rotations ,该参数保存要旋转的 Deque 中元素的旋转次数。

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

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

方案一:

rotate(2);
   
echo("Rotated Deque\n");
  
// Display the Deque elements
print_r($deck);
  
?>
输出:
Elements of Deque
Ds\Deque Object
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
)
Rotated Deque
Ds\Deque Object
(
    [0] => 3
    [1] => 4
    [2] => 5
    [3] => 6
    [4] => 1
    [5] => 2
)

方案二:

rotate(2);
   
echo("Rotated Deque\n");
  
// Display the Deque elements
print_r($deck);
  
?>
输出:
Elements of Deque
Ds\Deque Object
(
    [0] => geeks
    [1] => for
    [2] => geeks
    [3] => practice
)
Rotated Deque
Ds\Deque Object
(
    [0] => geeks
    [1] => practice
    [2] => geeks
    [3] => for
)

参考: http: PHP。 PHP