PHP is_null() function

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.

SYNATX:

  1. bool is_null ( mixed $var )  

Parameter

ParameterDescriptionIs compulsory
varThe variable being evaluated.compulsory

Return Type:

The PHP is_null() function returns true if var is null, otherwise false.

Important Note:

We can unset the variable value by using the unset function.

Example 1

<?php  
    $var1 = TRUE;  
    if (is_null($var1))  
        {  
            echo 'Variable is  NULL';  
        }  
        else  
        {  
            echo 'Variable is not NULL';  
        }  
?>  

output

Variable is not NULL

Example 2

<?php  
    $x= 100;  
    unset($x);  
    echo is_null($x);  
?>  

output

1

Example 3

<?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");  
?>  

output

Ture

False