strcmp函数_strcmp

strcmp函数

strcmp函数

strcmp() compares two strings and gives -1, 0 or 1 depending on wheather the first string is "smaller", equal to or greater than the second one.

strcmp()比较两个字符串,并根据小麦的情况给出-1、0或1,第一个字符串“较小”,等于或大于第二个字符串。

< ?php echo strcmp('aa','bb'); // prints -1 echo strcmp('bb','bb'); // prints 0 echo strcmp('zz','yy'); // prints 1 ?>

<?php echo strcmp('aa','bb'); //打印-1 echo strcmp('bb','bb'); //打印0 echo strcmp('zz','yy'); //打印1?>

Thus being said there's an error in the php certification guide that explains the strcasecmp() function, which is the same as strcmp() only case insensitive. There is a snippet in the book that goes like: < ?php $a = 'hello'; if (strcasecmp($a, 'HELLO')) { echo 'the same'; }?> The book says that the echo will be executed but it will not, as the comparison will return 0, since 'hello' and 'HELLO' are the same string when regarded at case-insensitively.

因此,据说php认证指南中有一个错误,解释了strcasecmp()函数,该函数与strcmp()相同,只是不区分大小写。 书中有一个摘要,如下所示:<?php $ a ='hello'; 如果(strcasecmp($ a,'HELLO')){回显'相同'; }?>这本书说, echo将被执行,但不会执行,因为比较将返回0,因为当区分大小写时,'hello'和'HELLO'是相同的字符串。

Tell your friends about this post on Facebook and Twitter

FacebookTwitter上告诉您的朋友有关此帖子的信息

翻译自: https://www.phpied.com/strcmp/

strcmp函数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值