Check whether a variable is empty – PHP

<?php
 // Example 1
 $string="";
 if(empty($string))
  echo "Empty string";
 else
  echo "Not an empty string"; //Empty string
?>

<?php
 // Example 2
 $strng="Test";
 if(empty($strng))
  echo "Empty string";
 else
  echo "Not an empty string";  //Not an empty string
?>
Share

Leave a Reply

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