使用'=='和'strcmp()'进行字符串比较 [英] String comparison using '==' vs. 'strcmp()'
本文介绍了使用'=='和'strcmp()'进行字符串比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
似乎PHP的===
运算符区分大小写.那么有没有理由使用strcmp()
?
It seems that PHP's ===
operator is case sensitive. So is there a reason to use strcmp()
?
执行以下操作是否安全?
Is it safe to do something like the following?
if ($password === $password2) { ... }
推荐答案
使用它的原因是因为 strcmp
The reason to use it is because strcmp
返回<如果str1小于str2,则为0;否则,为0.如果str1大于str2,则> 0;如果相等,则为0.
returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.
===
仅返回true
或false
,它不会告诉您哪个是更大"的字符串.
===
only returns true
or false
, it doesn't tell you which is the "greater" string.
这篇关于使用'=='和'strcmp()'进行字符串比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文