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
?>

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>