note 44302 added to function.empty
| From: | ChrisM at rn2 dot php dot net | Date: | Tue, 20 Jul 2004 20:38:17 +0000 |
| Subject: | note 44302 added to function.empty | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-73737@lists.php.net to get a copy of this message | ||
This G_empty() function worked good for me to overcome all the hassles with the empty() check not
working properly.
Try it.
// this function replaces PHP empty()
function G_empty($var)
{
if( ($var === 0) || ($var === 0.0) || ($var === '0') ) return(FALSE);
else return(empty($var));
}
$a = 0; //integer a
$b = '0'; //string '0'
$c = 0.0; //decimal 0.0
$d = '0.0'; //string '0.0'
$e = (int) 0; // integer 0
$f = '';
$g = NULL;
$h = 0.00; //decimal 0.00
echo (empty($a)? "empty\n": "not empty\n"); //result empty, wrong
echo (empty($b)? "empty\n": "not empty\n"); //result empty, wrong
echo (empty($c)? "empty\n": "not empty\n"); //result empty, wrong
echo (empty($d)? "empty\n": "not empty\n"); //result not empty, correct
echo (empty($e)? "empty\n": "not empty\n"); //result empty, wrong
echo (empty($f)? "empty\n": "not empty\n"); //result empty, correct
echo (empty($g)? "empty\n": "not empty\n"); //result empty, correct
echo (empty($h)? "empty\n": "not empty\n"); //result empty, correct
echo "--------\n";
echo (G_empty($a)? "empty\n": "not empty\n"); //result not empty, correct
echo (G_empty($b)? "empty\n": "not empty\n"); //result not empty, correct
echo (G_empty($c)? "empty\n": "not empty\n"); //result not empty, correct
echo (G_empty($d)? "empty\n": "not empty\n"); //result not empty, correct
echo (G_empty($e)? "empty\n": "not empty\n"); //result not empty, correct
echo (G_empty($f)? "empty\n": "not empty\n"); //result empty, correct
echo (G_empty($g)? "empty\n": "not empty\n"); //result empty, correct
echo (G_empty($h)? "empty\n": "not empty\n"); //result not empty, correct
----
Manual Page -- http://www.php.net/manual/en/function.empty.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44302
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44302&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44302&report=yes
Search -- http://master.php.net/manage/user-notes.php