PHP natsort() 函数

PHP 教程 · 2019-01-22 20:58:05

实例

对数组进行排序:

<?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);
?>

定义和用法

natsort() 函数用"自然排序"算法对数组进行排序。键值保留它们原始的键名。

在自然排序算法中,数字 2 小于 数字 10。在计算机排序算法中,10 小于 2,因为 "10" 中的第一个数字小于 2。

语法

natsort(array)

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

技术细节

返回值: 如果成功则返回 TRUE,如果失败则返回 FALSE。
PHP 版本: 4+
更新日志: 自 PHP 5.2.10 起,当用 0 填充数字字符串时(例如 '00006'),将忽略 0。

点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

Head First Rails

Head First Rails

David Griffiths / O'Reilly Media / 2008-12-30 / USD 49.99

Figure its about time that you hop on the Ruby on Rails bandwagon? You've heard that it'll increase your productivity exponentially, and allow you to created full fledged web applications with minimal......一起来看看 《Head First Rails》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具