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

PHP
WINDOWS下安装MySQL
PHP 制作 网站/服务器 监视脚本
用PHP和CSS制作活动按钮
PHP 单件模式
PHP MVC模式,类封装以及HACK
PHP 中使用正则表达式
PHP 防止 SQL 注入攻击
PHP 跨站点脚本攻击
PHP 防止用户操纵 GET 变量
PHP 防止远程表单提交

PHP 中的 natsort() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 416 ::
收藏到网摘: 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

登陆 | 还没注册?