为什么会这样happen http://sandbox.onlinephpfunctions.com/code/d5fff6ee86bc7c62d7624a39a1070cff770ad4aa?
<?php $result = true ;
if($result == 'SOME TEXT')
echo 'why is this true? why is this printed?';
else
echo 'when this should be printed?'
?>
请解释一下,我不是在寻找替代方法。
在您的表达式中,您正在将布尔值与字符串进行比较。字符串被强制为true
.
参考:http://www.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting http://www.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting
如前所述,使用===
比较值和类型。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)