Ds \ Vector::reverse()函數是PHP中的內置函數,用於就地反轉矢量元素。
用法:
void public Ds\Vector::reverse( void )
參數:該函數不接受任何參數。
返回值:該函數不返回任何值。
以下示例程序旨在說明PHP中的Ds \ Vector::reverse()函數:
程序1:
<?php
// Create new Vector
$arr = new \Ds\Vector([1, 2, 3, 4, 5]);
// Display the elements
print_r($arr);
echo("Vector after reversing\n");
// Use reverse() function to reverse
// the vector elements and display it
$arr->reverse();
print_r($arr);
?>
輸出:
Ds\Vector Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) Vector after reversing Ds\Vector Object ( [0] => 5 [1] => 4 [2] => 3 [3] => 2 [4] => 1 )
程序2:
<?php
// Create new Vector
$arr = new \Ds\Vector(["Geeks", "GFG",
"Computer", "Science", "Portal"]);
// Display the elements
print_r($arr);
echo("Vector after reversing\n");
// Use reverse() function to reverse
// the vector elements and display it
$arr->reverse();
print_r($arr);
?>
輸出:
Ds\Vector Object ( [0] => Geeks [1] => GFG [2] => Computer [3] => Science [4] => Portal ) Vector after reversing Ds\Vector Object ( [0] => Portal [1] => Science [2] => Computer [3] => GFG [4] => Geeks )
參考: https://www.php.net/manual/en/ds-vector.reverse.php
相關用法
- PHP Ds\Set reverse()用法及代碼示例
- PHP Ds\Map reverse()用法及代碼示例
- p5.js reverse()用法及代碼示例
- PHP Ds\Deque reverse()用法及代碼示例
- PHP Ds\Sequence reverse()用法及代碼示例
- Node.js dnsPromises.reverse()用法及代碼示例
- PHP max( )用法及代碼示例
注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | Ds\Vector reverse() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。