note 42591 added to function.empty

From: Date: Sat, 22 May 2004 14:09:52 +0000
Subject: note 42591 added to function.empty
Groups: php.notes 
Request: Send a blank email to php-notes+get-69962@lists.php.net to get a copy of this message
Note the exceptions when it comes to decimal numbers: <?php $a = 0.00; $b = '0.00'; echo (empty($a)? "empty": "not empty"); //result empty echo (empty($b)? "empty": "not empty"); //result not empty //BUT... $c = intval($b); echo (empty($c)? "empty": "not empty"); //result empty ?> For those of you using MySQL, if you have a table with a column of decimal type, when you do a SELECT, your data will be returned as a string, so you'll need to do apply intval() before testing for empty. e.g. TABLE t has columns id MEDIUMINT and d DECIMAL(4,2) and contains 1 row where id=1, d=0.00 <?php $q = "SELECT * FROM t"; $res = mysql_query($q); $row = mysql_fetch_assoc($res); echo (empty($row['d'])? "empty": "not empty"); //result not empty ?> ---- Manual Page -- http://www.php.net/manual/en/function.empty.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42591 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42591&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42591&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69962) next »