note 65560 deleted from function.is-null by bjori
| From: | bjori@php.net | Date: | Wed, 03 May 2006 13:04:23 +0000 |
| Subject: | note 65560 deleted from function.is-null by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-110449@lists.php.net to get a copy of this message | ||
Note Submitter: smunks at yahoo dot com
Reason: in docs
----
A follow up warning to jsjacobs at piercedmedia dot com's entry.
empty() is true even for variables set to 0.
<?php
print '$test = ""<br>';
$test = '';
if(empty($test))
print '$test is Empty<BR>';
else
print '$test is Not Empty<BR>';
if(empty($test) && $test != '0')
print '$test is Empty and != "0"<BR>';
else
print '$test is (Not Empty) OR ($test = "0")<BR>';
if(empty($test) && $test != 0)
print '$test is Empty and != 0<BR>';
else
print '$test is (Not Empty) OR ($test = 0)<BR>';
print '<br>$test = 0<br>';
$test = 0;
if(empty($test))
print '$test is Empty<BR>';
else
print '$test is Not Empty<BR>';
if(empty($test) && $test != '0')
print '$test is Empty and != "0"<BR>';
else
print '$test is (Not Empty) OR ($test = "0")<BR>';
if(empty($test) && $test != 0)
print '$test is Empty and != 0<BR>';
else
print '$test is (Not Empty) OR ($test = 0)<BR>';
?>
Generates:
$test = ""
$test is Empty
$test is Empty and != "0"
$test is (Not Empty) OR ($test = 0)
$test = 0
$test is Empty
$test is (Not Empty) OR ($test = "0")
$test is (Not Empty) OR ($test = 0)
Hence to determine if a variable is '' or 0 one must use:
if(empty($test) && $test != '0'), usefull when updating a mysql database field to
NULL.
read more at: http://se2.php.net/manual/en/function.empty.php