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

查看所有标签

Lighttpd

Lighttpd

Andre Bogus / Packt Publishing / 2008-10 / 39.99

This is your fast guide to getting started and getting inside the Lighttpd web server. Written from a developer's perspective, this book helps you understand Lighttpd, and get it set up as securely an......一起来看看 《Lighttpd》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

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

在线 XML 格式化压缩工具

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

HSV CMYK互换工具