note 44302 deleted from function.empty by tomsommer

From: Date: Tue, 20 Jul 2004 21:05:10 +0000
Subject: note 44302 deleted from function.empty by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73741@lists.php.net to get a copy of this message
Note Submitter: Chris M. ---- 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

« previous php.notes (#73741) next »