tag tag - 1 year ago 389
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"
"0" "1"

$converted_res = "true";
$converted_res = "false";

I've tried:

$converted_res = string($res);
$converted_res = String($res);

but it tells me
are not recognized functions. How do I convert this boolean to a string in the format "true" or "false" in php?

Answer Source
$converted_res = ($res) ? 'true' : 'false';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download