rsort
對數組逆向排序
rsort()
函數對數值數組進行降序排序。
提示:請使用sort()函數對數值數組進行升序排序。
對數組$cars 中的元素按字母進行降序排序:
<?php $cars = array ( "Volvo" , "BMW" , "Toyota" ) ; rsort ( $cars ) ; ?>
親自試一試
對數組$numbers 中的元素按數字進行降序排序:
<?php $numbers = array ( 4 , 6 , 2 , 22 , 11 ) ; rsort ( $numbers ) ; ?>
親自試一試
把項目作為數字來比較,並對數組$cars 中的元素進行降序排序:
<?php $cars = array ( "Volvo" , "BMW" , "Toyota" ) ; rsort ( $cars , SORT_NUMERIC ) ; ?>
親自試一試
rsort ( array , sortingtype ) ;
參數 | 描述 |
---|---|
array | 必需。規定要進行排序的數組。 |
sortingtype |
可選。規定如何比較數組的元素/項目。可能的值:
|
rsort()
函數對數組的元素按照鍵值進行逆向排序。與arsort()
的功能基本相同。
註釋:該函數為array中的單元賦予新的鍵名。這將刪除原有的鍵名而不僅是重新排序。
如果成功則返回TRUE,否則返回FALSE。
可選的第二個參數包含另外的排序標誌。