On php documentation we can see:
JavaScript
x
"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
If I have for example $var1 = 0;
and $var2 = 0;
on php I can do:
JavaScript
if (empty($var1)){
echo "empty";
}
But I cant do this:
JavaScript
if (empty($var1 && $var2)){
echo "empty";
}
How can I do for check if the two vars are equal to 0 on the same if
?
Advertisement
Answer
You can run
JavaScript
if( $var1 === 0 && $var2 === 0 ) {
// both empty
}
to see if those two variable are both holding the integer zero.
If you want a more loose type check (see if the variables are zero, or false, or null, for example), you can do:
JavaScript
if( empty($var1) && empty($var2) ) {
// both empty
}
If (based on your question) you wanted to see if the variable holds the string "0"
, you would do it like this:
JavaScript
if( $var1 === "0" && $var2 === "0" ) {
// both are the string "0"
}