note 29198 added to function.empty

From: Date: Wed, 05 Feb 2003 21:49:19 +0000
Subject: note 29198 added to function.empty
Groups: php.notes 
Request: Send a blank email to php-notes+get-43481@lists.php.net to get a copy of this message
in regards to empty() and isset().. it seems that they will ALWAYS return true with "" in an array element: if(empty($array[element])){ echo "it is empty"; }else{ echo "not empty"; } it shows that when that array element is pulled from an empty sql table (mysql) using a blank (empty) form input field the "is empty" string will NEVER be ran because either "" "0" or "none" and null are all considered to be a value of some kind. also i find that isset() is not a very good choice to check unused form fields because when the variable is passed from the form to the script it has "something" in it. what that something is we might never know..: <input type="text" name="foo" value="array[element]"> now if in the form you just press submit without typing anything in the box then empty and isset consideres that array[element] as being full of something and isset consideres it as set since it tried to get a blank field from an sql record.. i havent quite figured out what system will work for testing "empty" variables .. i believe they are either !isset or they have something in them if isset=true.. -- http://www.php.net/manual/en/function.empty.php http://master.php.net/manage/user-notes.php?action=edit+29198 http://master.php.net/manage/user-notes.php?action=delete+29198 http://master.php.net/manage/user-notes.php?action=reject+29198

« previous php.notes (#43481) next »