Possible Duplicate:
PHP - Get bool to echo false when false
Given the following test.php:
<?php
echo TRUE . "\n"; // prints "1\n"
echo FALSE . "\n"; // prints "\n"
?>
Why doesn't php -f test.php
print TRUE
or FALSE
? More importantly, in the FALSE
case, why doesn't it print anything?
From the manual:
A boolean TRUE value is converted to the string "1". Boolean FALSE is converted to "" (the empty string). This allows conversion back and forth between boolean and string values.
Because false == '';
do this to print booleans:
$bool = false;
echo $bool ? 'true' : 'false';
or...
echo $bool ? 'yes' : 'no';
echo $bool ? '1' : '0';
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