To convert from a Boolean to a string
new Boolean(new String("hej".equalsIgnoreCase("HEJ")).toString(); |
and then from a string to a boolean
boolean theValue = Boolean.parseBoolean(strBoolean); |
To convert from a Boolean to a string
new Boolean(new String("hej".equalsIgnoreCase("HEJ")).toString(); |
and then from a string to a boolean
boolean theValue = Boolean.parseBoolean(strBoolean); |
The first idea that comes into mind for doing this is to simply make a typecast of the boolean variable to a string and use that (which works)
$testVar = false; echo (string)$testVar; //will output a empty string (as that evaluates to false) $testVar = true; echo (string)$testVar; //will output 1 (as that evaluates to true) |
but what if the requirement is that the string should say true or false
$testVar = false; echo $testVar ? 'true' : 'false'; //will output false $testVar = true; echo $testVar ? 'true' : 'false'; //will output true |
(While the above example might seam useless I recently had to do this for a db insert)