Possible Duplicate:
Why does PHP consider 0 to be equal to a string?
我有这段代码:
$o['group'] = "prueba";
if( $o['group'] == 0){
die("test");
}
为什么打印测试?一个字符串怎么可能等于零?
最佳答案
如果您希望它与字符串完全匹配,请尝试使用三个等号的精确类型
if( $o['group'] === 0){
==
将字符串与整数 0 进行比较时始终计算为 true
'a string' == 0 also evaluates to true because any string is converted into an integer when compared with an integer. If PHP can't properly convert the string then it is evaluated as 0. So 0 is equal to 0, which equates as true.
来自 here
关于php字符串与0整数比较返回true?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8671942/