php strnatcmp()函数的用法总结

yipeiwu_com5年前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学习之字符串比较和查找

1. 字符串比较 在PHP中,可以用==(双等号)或者 ===(三等号)来比较字符串。两者的区别是双等号不比较类型,三等号会比较类型,它不转换类型;用双等号进行比较时,如果等号左右两边有...

PHP实现算式验证码和汉字验证码实例

在PHP网站开发中,验证码可以有效地保护我们的表单不被恶意提交,但是如果不使用算式验证码或者汉字验证码,仅仅使用简单的字母或者数字验证码,这样的验证码方案真的安全吗? 大家知道简单数字或...

ob_start(),ob_start('ob_gzhandler')使用

输出前使用尽量使用 ob_start();可以加快输出速度,适用NT 对unix类服务器 如果使用ob_start('ob_gzhandler');输出效率将更高...

浅析PHP substr,mb_substr以及mb_strcut的区别和用法

PHP substr()函数可以 分割文字,但要分割的文字如果包括中文字符往往会遇到问题,这时可以用mb_substr()/mb_strcut这个函数,mb_substr() /mb_s...

PHP下常用正则表达式整理

--------------------------------------------------------- 正则收藏 手机号码: $mode = "/^1[358]\d{9}/"...