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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
