标签:php
乳清这算是真的吗?
$val2=0;
//outputs that is an error123
if($val2=='error123'){
echo 'that is an error123
';
}else{
echo 'that is not an error123
';
}
解决方法:
您正在将字符串与整数进行比较.为了进行比较,首先将字符串转换为整数.当“ error123”转换为整数时,它变为0.
echo intval("error123");
结果:
0
If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically.
有一个快速参考页PHP type comparison tables,向您显示各种比较的结果.请参阅表格“与==的宽松比较”.关于这个问题,有趣的部分是0 ==“ php”显示为TRUE.
如果您不希望类型变戏法,请使用===而不是==.
标签:php
来源: https://codeday.me/bug/20191012/1900902.html