2012-09-29 153 views
-3

可能重复:
Why does PHP consider 0 to be equal to a string?
php string comparasion to 0 integer returns true?IF语句总是在PHP执行

看来,作为一个在PHP的if语句,其中一个功能some_function()返回零

<?php 
if(some_function() == "whatever_you_want") { ... } 

statem ent将始终执行,因为

<?php 
echo some_function() == "whatever_you_want"; 

然后是TRUE。

为什么要以这种直观的方式表现PHP?

+0

函数返回什么? “零”不是一回事。 – deceze

+1

将整数(0)与字符串进行比较的意义何在?如果你坚持这样做,那么使用'==='运算符。 – Havelock

+0

http://php.net/manual/en/types.comparisons.php – Sotiris

回答