PHP How to check if a variable is null?

I am explaining you, how to check if a variable is null or not in PHP. I will check null values through is_null() function in PHP.

Example :

<?php
  $nullvar = NULL;  
  $notnull='Webdeveloperindia.in'; 
  if(is_null($nullvar)){
    echo '$nullvar is null.';
  }
   echo '<br />';
  if(is_null($notnull)){
    echo $notnull.' is null.';
  }else
  {
  	 echo $notnull.' is not null.';
  }
?>

Output :

$nullvar is null.
Webdeveloperindia.in is not null.

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 8 = 14