isset() VS empty()

It might be confusing as far as i red on many forums that fails to explain the diffrence between isset() and empty().
So let me put it this way :

 

Isset() checks if a variable has a value including ( Flase , 0 , or Empty string) , But not NULL.
Returns TRUE if var exists; FALSE otherwise.

 

On the other hand the empty() function checks if the variable has an empty value empty string , 0, NULL ,or False. Returns FALSE if var has a non-empty and non-zero value.

 

Comparison example on both isset() and empty()

 

<?php
$var = 0;

// Evaluates to true because $var is empty
if (empty($var)) {
echo '$var is either 0, empty, or not set at all';
}

// Evaluates as true because $var is set
if (isset($var)) {
echo '$var is set even though it is empty';
}
?>

 

For more information and examples visit the following links.

http://www.php.net/isset

http://www.php.net/empty

 

m0o

This entry was posted in Bahrain. Bookmark the permalink.

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>