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

查看所有标签

HTML & XHTML

HTML & XHTML

Chuck Musciano、Bill Kennedy / O'Reilly Media / 2006-10-27 / GBP 39.99

"...lucid, in-depth descriptions of the behavior of every HTML tag on every major browser and platform, plus enough dry humor to make the book a pleasure to read." --Edward Mendelson, PC Magazine "Whe......一起来看看 《HTML & XHTML》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具