I have a Boolean variable which I want to convert to a string:
$res = true;
I need the converted value to be of the format: "true" "false"
, not "0" "1"
$converted_res = "true"; $converted_res = "false";
I've tried:
$converted_res = string($res); $converted_res = String($res);
But it tells me that string
and String
are not recognized functions.
How do I convert this Boolean to a string in the format of "true"
or "false"
in PHP?
There are two methods by which we can convert a boolean to String: 1) Method 1: Using String. valueOf(boolean b): This method accepts the boolean argument and converts it into an equivalent String value.
Python convert boolean to string To convert boolean to string in python, we will use str(bool) and then it will be converted to string.
Convert Boolean values (TRUE or FALSE) to text in Excel For example, the original formula is =B2>C2, you can change the formula to =IF(B2>C2,"Yes","NO"). This new formula will change TRUE to Yes, and change FALSE to No.
Simplest solution:
$converted_res = $res ? 'true' : 'false';
The function var_export returns a string representation of a variable, so you could do this:
var_export($res, true);
The second argument tells the function to return the string instead of echoing it.
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