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

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 中的 natcasesort() 函数


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

Definition and Usage
定义和用法

The natcasesort() function sorts an array by using a "natural order" algorithm. The values keep their original keys.
natcasesort()函数的作用是:用“自然排序[natural order]”算法对数组进行不区分大小写字母的排序。数组内所有值的键保持不变。

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 is case-insensitive.
这个函数不区分大小写[case-insensitive]。

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

Syntax
语法

natcasesort(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");
natsort($temp_files);
echo "Natural order: ";
print_r($temp_files);
echo "<br />";
natcasesort($temp_files);
echo "Natural order case insensitve: ";
print_r($temp_files);
?>

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

Natural order:
Array
(
[0] => Temp10.txt
[1] => Temp22.txt
[2] => temp1.txt
[4] => temp2.txt
[3] => temp15.txt
)
Natural order case insensitve:
Array
(
[2] => temp1.txt
[4] => temp2.txt
[0] => Temp10.txt
[3] => temp15.txt
[1] => Temp22.txt
)

评论 (0) All

登陆 | 还没注册?