natsort



PHP natsort() 函数

定义和用法

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

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

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

语法

natsort(array)

参数 描述
array 必需。规定要进行排序的数组。

例子

本函数所用的自然排序算法,与通常的计算机字符串排序算法(用于 sort())的区别,见下面示例:

";

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
)

温馨提示: 本文最后更新于2024-12-31 20:25:34,某些文章具有时效性,若有错误或已失效,请在下方 留言或联系 蚂蚁官方
© 版权声明
THE END
喜欢就支持一下吧
点赞13赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容