当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > natsort() 函数

PHP
PHP 安全邮件
MySQL 介绍
连接 MySQL
创建 MySQL
MySQL 插入记录
MySQL 选择记录
MySQL Where
MySQL Order By
MySQL 记录更新
MySQL 删除记录
PHP ODBC
XML Expat Parser
XML SimpleXML
PHP 数组参考
PHP Calendar
PHP Date
PHP Directory
PHP Filesystem
PHP FTP
PHP HTTP

PHP 中的 natsort() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 418 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The natsort() function sorts an array by using a "natural order" algorithm. The values keep their original keys.
natsort()函数的作用是用“自然排序”算法对数组排序。数组内所有值的键保持不变。

In a natural algorithm, the number 2 is less than the number 10. In computer sorting, 10 is less than 2, because the first number in "10" is less than 2.
在“自然运算法则[natural algorithm]”中,“2”小于“10”;在计算机排序运算法则中,“10”是小于“2”的,因为“10”的第一个数字“1”小于“2”。

This function returns TRUE on success, or FALSE on failure.
如果成功,则该函数返回True;失败则返回False。

Syntax
语法

natsort(array)

Parameter
参数
Description
描述
array Required. Specifies the array to sort
必要函数。指定需要进行排序的数组


Example
案例

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

The output of the code above will be:
上述代码将输出下面的结果:

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
) 

评论 (0) All

登陆 | 还没注册?