The is_null
method can be used to check if a variable is NULL
or not.
is_null(mixed $value): bool
The is_null
method returns true
if the passed value is NULL
. Otherwise, it returns false
.
<?phpprintIsNull($test); // undefined variable is NULL$test = NULL;printIsNull($test);$test = 0;printIsNull($test);$test = 'NULL';printIsNull($test);function printIsNull($test){echo "The Value is: ";var_dump($test);echo "Is null: ";var_dump(is_null($test));echo "---------\n\n";}?>
In the code above:
We use the is_null
method to check if a variable is NULL
or not.
For the undeclared variable and for the value NULL
, the is_null
method returns true
.
But for the values 0(int)
and 'NULL'(string)
, the is_null
method returns false
because they are not NULL
values.