tag tag - 6 months ago 160
PHP Question

How to Convert Boolean to String

I have a boolean variable which I want to convert to a string

$res = true;


I need it the converted value to also be in 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
string
and
String
are not recognized functions. How do I convert this boolean to a string in the format "true" or "false" in php?

Answer
$converted_res = ($res) ? 'true' : 'false';
Comments