Home > Chỉ dẫn lập trình > isset vs empty in PHP

isset vs empty in PHP

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()

$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’;

Categories: Chỉ dẫn lập trình Tags:
  1. Chưa có bình luận nào.
Content (You can use Yahoo! Messenger Emoticons :D = smile)