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. Quote Link to comment Share on other sites More sharing options...
Jabop Posted March 16, 2008 Share Posted March 16, 2008 Messed up post! Oops Quote Link to comment 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) Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.