View Full Version : php null values

07-25-2008, 03:26 AM
hi ,

can i replace this line

if($pluOnSite == "" or $pluOnSite == NULL or $pluOnSite == 0){}


if($pluOnSite) {}

07-25-2008, 03:39 AM
Simply put, no. It doesn't do the same thing, if you have what you have now then if the value does equal null or whatever it won't run the if statement, they are completely different statements.

07-25-2008, 04:07 AM
Take a look at the comparison tables (http://www.php.net/manual/en/types.comparisons.php) in the PHP appendix. I've found that using empty() (http://www.php.net/manual/en/function.empty.php) is sufficient in most cases.

07-25-2008, 05:57 AM
That was my mistake i mean to say


i think empty() is the best function. Thanks all

07-25-2008, 09:11 AM
No, you're right in you're first post mate. PHP's weak datatypes allow you to treat all of these (source: http://ca3.php.net/manual/en/language.types.boolean.php):

the boolean FALSE itself
the integer 0 (zero)
the float 0.0 (zero)
the empty string, and the string "0"
an array with zero elements
an object with zero member variables (PHP 4 only)
the special type NULL (including unset variables)
SimpleXML objects created from empty tags

as a boolean false. These will all fail in an identical ( false === null) test, but will pass a comparison test with juggling.