Ds \ Vector::rotate()函數是PHP中的一個內置函數,用於將數組元素旋轉給定的旋轉次數。旋轉也就地發生。
用法:
void public Ds\Vector::rotate( $rotations )
參數:該函數接受單個參數$rotations,該參數保存轉數。
返回值:該函數不返回任何值。
以下示例程序旨在說明PHP中的Ds \ Vector::rotate()函數:
程序1:
<?php
// Create new Vector
$vect = new \Ds\Vector([1, 2, 3, 4, 5]);
echo("Original Vector\n");
// Display the Vector elements
print_r($vect);
// Use rotate() function to rotate
// the vector elements
$vect->rotate(3);
echo("\nVector after rotating by 3 places\n");
// Display the Vector elements
print_r($vect);
?>
輸出:
Original Vector Ds\Vector Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) Vector after rotating by 3 places Ds\Vector Object ( [0] => 4 [1] => 5 [2] => 1 [3] => 2 [4] => 3 )
程序2:當旋轉數大於向量中的元素數時。
<?php
// Create new Vector
$vect = new \Ds\Vector([1, 2, 3, 4, 5]);
echo("Original Vector\n");
// Display the Vector elements
print_r($vect);
// Use rotate() function to rotate
// the vector elements
$vect->rotate(6);
echo("\nVector after rotating by 6 places\n");
// Display the Vector elements
print_r($vect);
?>
輸出:
Original Vector Ds\Vector Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) Vector after rotating by 6 places Ds\Vector Object ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 [4] => 1 )
參考: http://php.net/manual/en/ds-vector.rotate.php
相關用法
- p5.js rotate()用法及代碼示例
- CSS hue-rotate()用法及代碼示例
- CSS rotate()用法及代碼示例
- PHP ImagickDraw rotate()用法及代碼示例
- Node.js GM rotate()用法及代碼示例
- PHP GmagickDraw rotate()用法及代碼示例
- PHP Ds\Deque rotate()用法及代碼示例
- PHP Ds\Sequence rotate()用法及代碼示例
注:本文由純淨天空篩選整理自barykrg大神的英文原創作品 PHP | Ds\Vector rotate() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。