PHP的错误条件 [英] php false place in condition
本文介绍了PHP的错误条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通常将false
与false
进行比较,其中false
在右侧:
Usually comparing with false
is done like this where false
is on right side:
if(strpos($str, 'php') !== false) {
// code
}
但是我也注意到左侧的各个地方false
But I have also noticed at various places false
on left side:
if(false !== strpos($str, 'php')) {
// code
}
据我了解,它们是一样的,为什么有些人将false
放在左侧?有什么特别的东西,我想念的吗?
As far as I understand, they are same then why some people put false
on left side? Is there anything special about it, something I am missing ?
推荐答案
那是开发人员发明的不专心的
Thats something inattentive developers invented
问题"
if ($var = false) { /* code */ }
解决方案
if (false = $var) { /* code */ }
最后一个失败,因此开发人员发现他错过了另外一个=
,!
,...在这里
Latter one will fail and thus the developer sees, that he misses an additional =
, !
, ... here
这篇关于PHP的错误条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文