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

相关文章

解决微信授权回调页面域名只能设置一个的问题

解决微信授权回调页面域名只能设置一个的问题

最终的解决方案是:https://github.com/liuyunzhuge/php_weixin_proxy,详细的介绍请往下阅读。 在做项目集成微信登录以及微信支付的时候,都需要进...

php中使用getimagesize获取图片、flash等文件的尺寸信息实例

如果你还想着通过解析swf文件头信息来获取flash文件的尺寸信息,那真的有点走远了。因为从PHP 4开始已经内置getimagesize函数来做这个事。其功能测定任何 GIF,JPG,...

mongodb和php的用法详解

Mognodb数据库连接. 默认格式 $m = new Mongo(); //这里采用默认连接本机的27017端口,当然也可以连接远程主机如 192.168.0.4:27017,如...

PHP整合PayPal支付

简单整理一下PHP项目整合PayPal支付功能。 一、表单的构建: <form method="post" name="form" action="https://www.pa...

php magic_quotes_gpc的一点认识与分析

blankyao 说“学习的过程就是不断的发现错误,不断的改正错误”; 先看下手册上怎么说的吧! 对一般人来说看下前两段就可以了 Magic Quotes 代码: Magic Quote...