To echo a boolean value, we can use the ternary operator ( ? ) in Php.
The is_bool() function checks whether a variable is a boolean or not. This function returns true (1) if the variable is a boolean, otherwise it returns false/nothing.
C does not have boolean data types, and normally uses integers for boolean testing. Zero is used to represent false, and One is used to represent true. For interpretation, Zero is interpreted as false and anything non-zero is interpreted as true.
In computer science, the Boolean (sometimes shortened to Bool) is a data type that has one of two possible values (usually denoted true and false) which is intended to represent the two truth values of logic and Boolean algebra.
echo $bool_val ? 'true' : 'false';
Or if you only want output when it's false:
echo !$bool_val ? 'false' : '';
This is the easiest way to do this:
$text = var_export($bool_value,true);
echo $text;
or
var_export($bool_value)
If the second argument is not true, it will output the result directly.
This will print out boolean value as it is, instead of 1/0.
$bool = false;
echo json_encode($bool); //false
No, since the other option is modifying the Zend engine, and one would be hard-pressed to call that a "better way".
Edit:
If you really wanted to, you could use an array:
$boolarray = Array(false => 'false', true => 'true');
echo $boolarray[false];
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