difference between is_null “== NULL” and “=== NULL” in PHP [duplicate]

假装没事ソ 提交于 2019-12-05 00:55:42

is_null($a) is same as $a === null.

($a === null is bit faster than is_null($a) for saving one function call, but it doesn't matter, just choose the style you like.)

For the difference of === and ==, read PHP type comparison tables

$a === null be true only if $a is null.

But for ==, the below also returns true.

null == false
null == 0
null == array()
null == ""
Igor Timoshenko

You should read this http://php.net/manual/en/language.operators.comparison.php. Also no need to use is_null function to check only on NULL. === is faster...

The === operator tests for the same value and the same TYPE. An empty string might evaluate to null, but it is not of the null type - hence this fails.

The == operator basically checks to see if they are pretty much the same - by that, do the evaluate to the same value. Being empty, this will evaluate to null, hence this fails.

The is_null function does a fairly thorough check - much more like the === operator.

Genosite

== checks if the value is equal e.g.:

>> "123" == 123
<< true

=== checks if the value & type are equal e.g.:

>> "123" === 123
<< false
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!