php strnatcmp()函数的用法总结

yipeiwu_com6年前PHP代码库

Definition and Usage
定义和用法
The strnatcmp() function compares two strings using a "natural" algorithm.
strnatcmp()函数的作用是:用自然运算法则比较字符串(大小写敏感)。

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.
在“自然运算法则”中,2比10小。在计算机序列当中,10比2小,因为“10”中的第一个数字是“1”,它小于2。

This function returns:
这个函数将返回下列值:

•0 - if the two strings are equal
0 – 如果字符串相等
•<0 - if string1 is less than string2
<0 – 如果string1小于string2
•>0 - if string1 is greater than string2
>0 – 如果string1大于string2
Syntax
语法

复制代码 代码如下:

strnatcmp(string1,string2)
Parameter参数 Description描述
string1 Required. Specifies the first string to compare
必要参数。指定参与比较的第一个字符串对象
string2 Required. Specifies the second string to compare
必要参数。指定参数比较的第二个字符串对象

Tips and Notes
注意点
Note: The strnatcmp() is case-sensitive.
注意:strnatcmp()函数是区分大小写的。

--------------------------------------------------------------------------------

Example
案例

复制代码 代码如下:

<?phpecho strnatcmp("2Hello world!","10Hello world!");echo "<br />";echo strnatcmp("10Hello world!","2Hello world!");?>

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

相关文章

PHP仿tp实现mvc框架基本设计思路与实现方法分析

本文实例讲述了PHP仿tp实现mvc框架基本设计思路与实现方法。分享给大家供大家参考,具体如下: 仿tp mvc基本设计与简单实现 一:文件加载常识 变量 常量 函数 类 文件加载的函数...

php 图片上添加透明度渐变的效果

复制代码 代码如下:<?php ////$strimgsrc = file_get_contents("/zb_users/upload/202003/e4lf1fxwbqa.jp...

php防止sql注入之过滤分页参数实例

本文实例讲述了php防止sql注入中过滤分页参数的方法。分享给大家供大家参考。具体分析如下: 就网络安全而言,在网络上不要相信任何输入信息,对于任何输入信息我们都必须进行参数过滤。对此,...

详解PHP实现定时任务的五种方法

定时运行任务对于一个网站来说,是一个比较重要的任务,比如定时发布文档,定时清理垃圾信息等,现在的网站大多数都是采用PHP动态语言开发的,而对于PHP的实现决定了它没有Java和.Net这...

php 正确解码javascript中通过escape编码后的字符

这是很久以前收集的一个,不知道谁写的了,但经过测试没有问题~ JavaScript代码 复制代码 代码如下: function phpUnescape($escstr) { preg_m...