PHP’s empty and isset function

The best way to check if a variable consists any value or is empty is to use empty function from PHP itself.

$myVar = 0;
if (empty($myVar))
{
echo '$myVar is either 0, empty, or not set at all';
}

Though, while coding in PHP it shouldn’t be confused with isset which checks if a variable is set or not set, whether that variable is empty.

$myVar = 0;
if (isset($myVar))
{
echo '$myVar is set even though it is empty';
}

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=""> <strike> <strong>