+ 1
Confused on this variable declaration in PHP.
So in a recent challenge for PHP I came across this line: $var = !null == 1 || (5 ==9 % 3); The variable $var equates to 1 after this declaration. I had thought the answer would equate to a boolean, seeing as how the it's checking to see whether two different conditions are true. I'm clearly incorrect, but I still don't know why.
1 Answer
+ 2
Never mind. I finally figured it out.
http://php.net/manual/en/language.types.boolean.php
PHP automatically converts any boolean to a value of '1' or '';
For example:
$var = 2 == 2;
echo $var; // This would print '1'
$var = 2 == 3;
echo $var; // This would any empty string.
This is not the case in something like python, where the first example would print 'True' and the second example would print 'False'.
Now I know.