I don't understand below output . found below expressions on php.net manual in boolean section.
<?php
var_dump(0 == 'all');// IS bool(true)
var_dump((string)0 == 'all'); //IS bool(false)
var_dump(0 === 'all'); // //IS bool(false)
?>
Definition and Usage The var_dump() function dumps information about one or more variables. The information holds type and value of the variable(s).
var_dump() displays values along with data types as output. print_r() displays only value as output. It does not have any return type. It will return a value that is in string format.
We have already learned that var_dump() function is used to display structured information (type and value) about one or more expressions. The function outputs its result directly to the browser.
If you compare an integer with a string, each string is converted to a number, so:
(0 == 'all') -> (0 == 0) -> true
The type conversion does not happen when the comparison is ===
or !==
because this also includes the comparison of the type:
(0 === 'all') -> (integer == string) -> false
The second line of code you wrote force the integer value to be considered as a string, and so the numerical cast doesn't happen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With