ivytony Posted March 16, 2008 Share Posted March 16, 2008 I am now kind of confused about !isset and empty. Can someone give me an example as explanation? I appreciate it. Link to comment https://forums.phpfreaks.com/topic/96334-difference-between-isset-and-empty/ Share on other sites More sharing options...
Jabop Posted March 16, 2008 Share Posted March 16, 2008 Messed up post! Oops Link to comment https://forums.phpfreaks.com/topic/96334-difference-between-isset-and-empty/#findComment-493129 Share on other sites More sharing options...
Jabop Posted March 16, 2008 Share Posted March 16, 2008 From my understanding, [pre]isset[/pre] checks if the variable is even defined. [pre]empty[/pre] checks if it is one of a few values. From the PHP website: empty — Determine whether a variable is empty Returns FALSE if var has a non-empty and non-zero value. The following things are considered to be empty: * "" (an empty string) * 0 (0 as an integer) * "0" (0 as a string) * NULL * FALSE * array() (an empty array) * var $var; (a variable declared, but without a value in a class) Link to comment https://forums.phpfreaks.com/topic/96334-difference-between-isset-and-empty/#findComment-493130 Share on other sites More sharing options...
discomatt Posted March 16, 2008 Share Posted March 16, 2008 This should help you understand. <?php $a = FALSE; $b = ""; $c = 0; $d = 'anything'; if (!isset($a) ) echo '$a is not set<br>'; if (empty($a) ) echo '$a is empty<br>'; if (!isset($b) ) echo '$b is not set<br>'; if (empty($b) ) echo '$b is empty<br>'; if (!isset($c) ) echo '$c is not set<br>'; if (empty($c) ) echo '$c is empty<br>'; if (!isset($d) ) echo '$d is not set<br>'; if (empty($d) ) echo '$d is empty<br>'; if (!isset($e) ) echo '$e is not set<br>'; if (empty($e) ) echo '$e is empty<br>'; ?> Returns $a is empty $b is empty $c is empty $e is not set $e is empty Link to comment https://forums.phpfreaks.com/topic/96334-difference-between-isset-and-empty/#findComment-493134 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.