Tuesday 21 November 2017

php - How to Convert Boolean to String

itemprop="text">

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?


itemprop="text">
class="normal">Answer



Simplest
solution:



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


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...