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

PHP
PHP Libxml
PHP Math
PHP Misc
PHP MySQL
PHP SimpleXML
PHP String
PHP XML
PHP Zip
PHP Mail
用PHP5的DirectoryIterators递归扫描目录
PHP 阻止SQL注入式攻击
PHP5面向对象 - 基础 - 类和对象
PHP5面向对象 - 基础 - 类的属性( public )
PHP5面向对象 - 基础 - 类的属性( private )
PHP5面向对象 - 基础 - 方法
PHP5面向对象 - 基础 - 对象的比较
php5面向对象 - 基础 - 构造函数
php5面向对象 - 基础 - 析构函数
用PHP控制用户的浏览器 - ob*函数的使用
PHP PDO 学习笔记

PHP 中的 natcasesort() 函数


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

登陆 | 还没注册?