PHP empty Function
What is empty() in PHP?
Explanation
empty function determines whether the given variable contains any value or not. This function does not return any error, if the variable does not exist.
Syntax:
empty(var_name)
Example :
<?php
$var1=0;
$str1='Hscripts.com';
if (empty($var1))
{
echo '$var1'." is empty or 0. <br />";
}
else
{
echo '$var1'." is not empty or 0. <br />";
}
if (empty($str1))
{
echo '$str1'." is empty or 0. <br />";
}
else
{
echo '$str1' ." string is not empty or 0. <br />";
}
?>
Result :
$var1 is empty or 0.
$str1 string is not empty or 0.
Check if variable is empty using
PHP empty function.