参数 | 描述 |
---|---|
array | 必需。规定要进行排序的数组。 |
本函数所用的自然排序算法,与通常的计算机字符串排序算法(用于 sort())的区别,见下面示例:
<?php $temp_files = array("temp15.txt","temp10.txt", "temp1.txt","temp22.txt","temp2.txt"); sort($temp_files); echo "Standard sorting: "; print_r($temp_files); echo "<br />"; natsort($temp_files); echo "Natural order: "; print_r($temp_files); ?>
输出:
Standard sorting: Array ( [0] => temp1.txt [1] => temp10.txt [2] => temp15.txt [3] => temp2.txt [4] => temp22.txt ) Natural order: Array ( [0] => temp1.txt [3] => temp2.txt [1] => temp10.txt [2] => temp15.txt [4] => temp22.txt )
制作:
http://www.7di.net 生活网搜集整理 参考: http://www.w3school.com.cn/php/func_array_natsort.asp |