note 45005 added to function.empty

From: Date: Mon, 23 Aug 2004 08:47:58 +0000
Subject: note 45005 added to function.empty
Groups: php.notes 
Request: Send a blank email to php-notes+get-75150@lists.php.net to get a copy of this message
ive found the empty() contruct extremely usefull. For some reason people seem to think its of little use, but thats not so. for example, form fields can be checked in 1 step by using empty(). (assuming a basic check of whether it was submitted and if submitted, that it was not empty.) <?php if (!empty($_POST['name'])) $name = $_POST['name']; ?> compared to isSet(), this saves an extra step. using !empty() will check if the variable is not empty, and if the variable doesnt exit, no warning is generated. with isSet(), to acheive the same result as the snippit above, you would need to do this: <?php if (isSet($_POST['name']) && $_POST['name']) $name = $_POST['name']; ?> so using !empty() reduces code clutter and improves readability, which IMO, makes this VERY usefull. ---- Manual Page -- http://www.php.net/manual/en/function.empty.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45005 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45005&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45005&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#75150) next »