By using the is_null function, we can check whether the variable is NULL or not. This function was introduced in PHP 4.0.4.
bool is_null ( mixed $var )
Parameter | Description | Is compulsory |
---|---|---|
var | The variable being evaluated. | compulsory |
The PHP is_null() function returns true if var is null, otherwise false.
We can unset the variable value by using the unset function.
<?php $var1 = TRUE; if (is_null($var1)) { echo 'Variable is NULL'; } else { echo 'Variable is not NULL'; } ?>
<?php $x= 100; unset($x); echo is_null($x); ?>
<?php $x = NULL; $y = "\0"; is_null($x) ? print_r("True\n") : print_r("False\n"); echo "<br/>"; is_null($y) ? print_r("True\n") : print_r("False\n"); ?>