natcasesort
用“自然排序”算法對數組進行不區分大小寫字母的排序
natcasesort()
函數用"自然排序"算法對數組進行排序。鍵值保留它們原始的鍵名。
在自然排序算法中,數字2 小於數字10。在計算機排序算法中,10 小於2,因為"10" 中的第一個數字小於2。
該函數對大小寫不敏感。
如果成功,該函數返回TRUE,如果失敗則返回FALSE。
<?php $temp_files = array ( "temp15.txt" , "Temp10.txt" , "temp1.txt" , "Temp22.txt" , "temp2.txt" ) ; natsort ( $temp_files ) ; echo "自然排序:" ; print_r ( $temp_files ) ; echo "<br />" ; natcasesort ( $temp_files ) ; echo "不區分大小寫的自然排序:" ; print_r ( $temp_files ) ; ?>
以上代碼的輸出:
自然排序: Array ( [0] => Temp10.txt [1] => Temp22.txt [2] => temp1.txt [4] => temp2.txt [3] => temp15.txt ) 不區分大小寫的自然順序: Array ( [2] => temp1.txt [4] => temp2.txt [0] => Temp10.txt [3] => temp15.txt [1] => Temp22.txt )
natcasesort ( array )
參數 | 描述 |
---|---|
array | 必需。規定要進行排序的數組。 |