Ds \ Deque::rotate()函数是PHP中的一个内置函数,用于将Deque的元素旋转给定的旋转数。
用法:
public Ds\Deque::rotate( $rotations ):void
参数:该函数接受单个参数$rotations,该参数保存要旋转Deque中元素的旋转数。
返回值:该函数不返回任何值。
以下示例程序旨在说明PHP中的Ds \ Deque::rotate()函数:
程序1:
<?php
// Declare a deque
$deck = new \Ds\Deque([1, 2, 3, 4, 5, 6]);
echo("Elements of Deque\n");
// Display the Deque elements
print_r($deck);
// Rotating the deque by 2 positions
$deck->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
)
程序2:
<?php
// Declare a deque
$deck = new \Ds\Deque(["geeks", "for", "geeks", "practice"]);
echo("Elements of Deque\n");
// Display the Deque elements
print_r($deck);
// Rotating the deque by 2 positions
$deck->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.net/manual/en/ds-deque.rotate.php
相关用法
- p5.js rotate()用法及代码示例
- CSS hue-rotate()用法及代码示例
- CSS rotate()用法及代码示例
- PHP Ds\Vector rotate()用法及代码示例
- PHP Ds\Sequence rotate()用法及代码示例
- PHP GmagickDraw rotate()用法及代码示例
- PHP ImagickDraw rotate()用法及代码示例
- Node.js GM rotate()用法及代码示例
注:本文由纯净天空筛选整理自barykrg大神的英文原创作品 PHP | Ds\Deque rotate() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
