Ds \ Sequence::rotate()函數是PHP中的一個內置函數,用於將序列元素旋轉給定的旋轉數。
用法:
void abstract public Ds\Sequence::rotate ( int $rotations )
參數:該函數接受單個參數$rotations,該參數保存轉數。
返回值:該函數不返回任何值。
以下示例程序旨在說明PHP中的Ds \ Sequence::rotate()函數:
程序1:
<?php
// Create new Sequence
$seq = new \Ds\Vector([1, 2, 3, 4, 5]);
echo("Original Sequence\n");
// Display the Sequence elements
print_r($seq);
// Use rotate() function to rotate
// the sequence elements
$seq->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
)
程序2:
<?php
// Create new Sequence
$seq = new \Ds\Vector(["Geeks", "for", "Geeks",
"Computer", "Science", "Portal"]);
echo("Original Sequence\n");
// Display the Sequence elements
print_r($seq);
// Use rotate() function to rotate
// the sequence elements
$seq->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
相關用法
- p5.js rotate()用法及代碼示例
- CSS hue-rotate()用法及代碼示例
- CSS rotate()用法及代碼示例
- PHP Ds\Vector rotate()用法及代碼示例
- PHP Ds\Deque rotate()用法及代碼示例
- PHP GmagickDraw rotate()用法及代碼示例
- PHP ImagickDraw rotate()用法及代碼示例
- Node.js GM rotate()用法及代碼示例
注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | Ds\Sequence rotate() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
