How can I convert string to boolean
?
$string = 'false';
$test_mode_mail = settype($string, 'boolean');
var_dump($test_mode_mail);
if($test_mode_mail) echo 'test mode is on.';
it returns,
boolean true
but it should be boolean false
.
booleancastingPHPstring
How can I convert string to boolean
?
$string = 'false';
$test_mode_mail = settype($string, 'boolean');
var_dump($test_mode_mail);
if($test_mode_mail) echo 'test mode is on.';
it returns,
boolean true
but it should be boolean false
.
Best Answer
This method was posted by @lauthiamkok in the comments. I'm posting it here as an answer to call more attention to it.
Depending on your needs, you should consider using
filter_var()
with theFILTER_VALIDATE_BOOLEAN
flag.