php true true true,php-为什么此评估为true
生活随笔
收集整理的這篇文章主要介紹了
php true true true,php-为什么此评估为true
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
標簽: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
總結
以上是生活随笔為你收集整理的php true true true,php-为什么此评估为true的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电影(《夜宴》,《满城尽带黄金甲》)的内
- 下一篇: 彼尔德和罗小黑是谁画的啊?