Answers for "string to boolean true php"

PHP
1

php convert string to boolean

/**
 * Strings always evaluate to boolean true unless they have a
 * value that's considered "empty" by PHP (taken from the
 * documentation for empty):
 * "" (an empty string) evaluates as false.
 * "0" (0 as a string) evaulates as false.
 * If you need to set a boolean based on the text value of a
 * string, then you'll need to check for the presence or
 * otherwise of that value.
 */
$boolean = $string === 'true' ? true: false;
Posted by: Guest on April-09-2020
2

true false php

""         -> false
"0"        -> false
"0.0"      -> true
"1"        -> true
"01"       -> true
"abc"      -> true
"true"     -> true
"false"    -> true
"null"     -> true
0          -> false
0.1        -> true
1          -> true
1.1        -> true
-42        -> true
"NAN"      -> true
0          -> false
NAN        -> true
null       -> false
true       -> true
false      -> false
[]         -> false
[""]       -> true
["0"]      -> true
[0]        -> true
[null]     -> true
["a"]      -> true
{}         -> true
{}         -> true
{"t":"s"}  -> true
{"c":null} -> true
Posted by: Guest on May-15-2021

Code answers related to "string to boolean true php"

Browse Popular Code Answers by Language