PHP is_null() and ==null [duplicate]
In PHP, what is the difference between is_null
and ==null
in PHP? What are the qualifications for both to return true?
Solution 1:
is_null
is the same as === null
. Both return true when a variable is null
(or unset).
Note that I'm using ===
and not ==
. ===
compares type as well as value.
Solution 2:
So you can understand it better:
$a = null;
$b = 0;
is_null($a) // TRUE
$a == null // TRUE
$a === null // TRUE
is_null($b) // FALSE
$b == null // TRUE
$b === null // FALSE
Solution 3:
There are a couple really good charts on the php.net site that show how different values react:
Type Comparison - php.net
Solution 4:
You can check the comparison between is_null() and null === $var
Good comparison between two