phpstring

How to Convert Boolean to String


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?


Solution

  • Simplest solution:

    $converted_res = $res ? 'true' : 'false';