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\"
You use strval() or (string) to convert to string in PHP. However, that does not convert boolean into the actual spelling of "true" or "false" so you must do that by yourself. Here's an example function:
function strbool($value)
{
return $value ? 'true' : 'false';
}
echo strbool(false); // "false"
echo strbool(true); // "true"