[PHP] 纯文本查看 复制代码 <?php
/*
* natsort:自然排序,根据字母与数字的组合方式进行排序比较
* sort()函数中 file14 < file2,因为第4位前者1小于后者2
* natcasesort():忽略大小写
*/
$array = array("file.txt", "File1.txt", "file14.txt", "file13.txt", "file2.txt");
print_r($array);
echo "<br/>";
natsort($array);
print_r($array);
echo "<br/>";
natcasesort($array);
print_r($array);
echo "<br/>";
输出结果:
Array ( [0] => file.txt [1] => File1.txt [2] => file14.txt [3] => file13.txt [4] => file2.txt )
Array ( [1] => File1.txt [0] => file.txt [4] => file2.txt [3] => file13.txt [2] => file14.txt )
Array ( [0] => file.txt [1] => File1.txt [4] => file2.txt [3] => file13.txt [2] => file14.txt )
Array ( [0] => file.txt [1] => File1.txt [4] => file2.txt [3] => file13.txt [2] => file14.txt ) |