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://www.codercto.com/courses/l/5.html

查看所有标签

The Probabilistic Method Second Edition

The Probabilistic Method Second Edition

Noga Alon、Joel H. Spencer / Wiley-Blackwell / 2000 / $121.95

The leading reference on probabilistic methods in combinatorics-now expanded and updated When it was first published in 1991, The Probabilistic Method became instantly the standard reference on one......一起来看看 《The Probabilistic Method Second Edition》 这本书的介绍吧!

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

在线XML、JSON转换工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

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

HEX HSV 互换工具