php true true true,php-为什么此评估为true
標(biāo)簽:php
乳清這算是真的嗎?
$val2=0;
//outputs that is an error123
if($val2=='error123'){
echo 'that is an error123
';
}else{
echo 'that is not an error123
';
}
解決方法:
您正在將字符串與整數(shù)進(jìn)行比較.為了進(jìn)行比較,首先將字符串轉(zhuǎn)換為整數(shù).當(dāng)“ error123”轉(zhuǎn)換為整數(shù)時(shí),它變?yōu)?.
echo intval("error123");
結(jié)果:
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.
有一個(gè)快速參考頁P(yáng)HP type comparison tables,向您顯示各種比較的結(jié)果.請參閱表格“與==的寬松比較”.關(guān)于這個(gè)問題,有趣的部分是0 ==“ php”顯示為TRUE.
如果您不希望類型變戲法,請使用===而不是==.
標(biāo)簽:php
來源: https://codeday.me/bug/20191012/1900902.html
總結(jié)
以上是生活随笔為你收集整理的php true true true,php-为什么此评估为true的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电影(《夜宴》,《满城尽带黄金甲》)的内
- 下一篇: php ip地址地区,PHP查询ip所在