natsort

王朝百科·作者佚名  2012-03-06  
宽屏版  字体: |||超大  

定义和用法natsort() 函数用自然顺序算法对给定数组中的元素排序。

natsort() 函数实现了“自然排序”,即数字从 1 到 9 的排序方法,字母从 a 到 z 的排序方法,短者优先。数组的索引与单元值保持关联。

如果成功,则该函数返回 TRUE,否则返回 FALSE。

语法natsort(array)

参数

描述

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 )

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝百科 版权所有