PHP is_null() function PHP

PHP is_null() function  

PHP is_null() function

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

Parameter Description Is compulsory
var The 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

  1. <?php  
  2.     $var1 = TRUE;  
  3.     if (is_null($var1))  
  4.         {  
  5.             echo 'Variable is  NULL';  
  6.         }  
  7.         else  
  8.         {  
  9.             echo 'Variable is not NULL';  
  10.         }  
  11. ?>  

PHP is_null() function

Example 2

  1. <?php  
  2.     $x= 100;  
  3.     unset($x);  
  4.     echo is_null($x);  
  5. ?>  

PHP is_null() function

Example 3

  1. <?php    
  2.     $x = NULL;   
  3.     $y = "\0";  
  4.     is_null($x) ? print_r("True\n") : print_r("False\n");  
  5.     echo "<br/>";  
  6.     is_null($y) ? print_r("True\n") : print_r("False\n");  
  7. ?>  

PHP is_null() function

Download free E-book of PHP


#askProgrammers
Learn Programming for Free


Join Programmers Community on Telegram


Talk with Experienced Programmers


Just drop a message, we will solve your queries