这三个方法都是对null的检查,
if($sth == NULL)
if($sth === NULL)
if(is_null($sth))
哪种方式合适?
最佳答案
他们检查三个不同的东西:
if ($sth == NULL)
这检查是否$sth
大致等于 null
.这意味着如果 $sth
这将通过实际上是0
.
if ($sth === NULL)
这检查是否$sth
正好等于 null
.
if (is_null($sth))
这会检查 $sth
的类型是 null 类型(其他测试 $sth
的值)。
===
和 is_null
技术总是会给出相同的答案; ==
有时会给出不同的答案。
关于php - 这些方法之间有什么区别,哪种方法可以正确检查 NULL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7050804/