In this article, you will learn how to check if a variable contains NULL or not in PHP. The is_null() function in PHP checks whether a variable is NULL or not.
This function returns true (1) if the variable is NULL, otherwise it returns false/nothing.
what is the syntax of the IS_NULL() function in php?
is_null(variable);
Parameter | Description |
---|---|
variable | Required. Specifies the variable to check |
examples of the IS_NULL() function
Example 1. In this example, we check whether a variable is NULL or not.
<?php
$a = 0;
echo "a is " . is_null($a) . "<br>";
$b = null;
echo "b is " . is_null($b) . "<br>";
$c = "null";
echo "c is " . is_null($c) . "<br>";
$d = NULL;
echo "d is " . is_null($d) . "<br>";
?>