Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有点惊讶,为什么会这样?!
$test = "THE STRING"; if($test == 0) echo "WTF!?"; else echo "OK";
输出是:
WTF!?
在上面一行中,我们只是将$test变量作为字符串,为什么根据上面的示例它等于0 !?
谢谢
你应该使用
===
为了这。PHP 使用它来进行严格的比较。
if($test === 0) { echo "WTF?" } else { echo "OK!"; }
试试这个:
if($test === 0){ echo "WTF?" } else { echo "OK!"; }
请改用此代码(使用三等号):
if($test === 0) echo "WTF!?"; else echo "OK";
阅读比较运算符了解更多信息。