PHP’s empty and isset function

without comments

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';
}

Written by admin

January 16th, 2009 at 11:11 am

Posted in Development

Tagged with ,

Leave a Reply