Is null or 0 php?
You hint at a deep question: when should an expression be true? Show Below, I will explain why what you are doing isn't working and how to fix it. In many languages This page tells us that if we have two variables being compared, then the variables are converted as follows (exiting the table at the first match)
So you are comparing a null versus a number. Therefore, both the null and the number are converted to boolean. This page tells
us that in such a conversion both Your expression now reads, But not what you want. This page provides a list of PHP's comparison operators.
The first comparator is the comparison you are using now. Note that it performs the conversions I mentioned earlier. Using the
second comparator will fix your problem. Since a null and a number are not of the same type, the Hope this helps. (PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8) is_null — Finds whether a variable is Descriptionis_null(mixed Parametersvalue The variable being evaluated. Return Values Returns ExamplesExample #1 is_null() example
(E_ALL);$foo = NULL; Notice: Undefined variable: inexistent in ... bool(true) bool(true) See Also
Malfist ¶ 14 years ago
george at fauxpanels dot com ¶ 13 years ago
contact dot 01834e2c at renegade334 dot me dot uk ¶ 7 years ago
ahamilton9 ¶ 4 months ago
ai dot unstmann at combase dot de ¶ 14 years ago
= array(null, true, false, 0, 1, '', "\0", "unset"); etimjoshua4 at gmail dot com ¶ 1 year ago
strrev xc.noxeh@ellij ¶ 14 years ago
normadize (a) gmail (d) com ¶ 10 years ago
michael at cannonbose dot com ¶ 18 years ago
Is NULL and 0 the same PHP?PHP considers null is equal to zero.
Is 0 considered empty PHP?PHP empty() Function
This function returns false if the variable exists and is not empty, otherwise it returns true. The following values evaluates to empty: 0. 0.0.
IS NULL == false in PHP?NULL essentially means a variable has no value assigned to it; false is a valid Boolean value, 0 is a valid integer value, and PHP has some fairly ugly conversions between 0 , "0" , "" , and false . Show activity on this post. Null is nothing, False is a bit, and 0 is (probably) 32 bits.
Is zero true or false in PHP?When converting to bool, the following values are considered false : the boolean false itself. the integer 0 (zero)
|