note 45005 deleted from function.empty by didou
| From: | didou@php.net | Date: | Sun, 18 May 2008 00:59:12 +0000 |
| Subject: | note 45005 deleted from function.empty by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-139486@lists.php.net to get a copy of this message | ||
Note Submitter: rehfeld.us
----
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.