strcmp函数_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函数