1/**
2 * Strings always evaluate to boolean true unless they have a
3 * value that's considered "empty" by PHP (taken from the
4 * documentation for empty):
5 * "" (an empty string) evaluates as false.
6 * "0" (0 as a string) evaulates as false.
7 * If you need to set a boolean based on the text value of a
8 * string, then you'll need to check for the presence or
9 * otherwise of that value.
10 */
11$boolean = $string === 'true' ? true: false;
1// (PHP 5 >= 5.5.0, PHP 7)
2// boolval — Get the boolean value of a variable
3boolval ( mixed $var ) : bool
4// Returns the boolean value of var.
1The is_bool() function checks whether a variable is a boolean or not. This function returns true (1) if the variable is a boolean, otherwise it returns false/nothing.
1Booleans can be one of two constants:
2true
3false
4These values are not case sensitive, therefore true is the same as TRUE
5
6booleans are also often used in control structures, either directly or as
7a result of an operation. For example:
8
9if ($waterDrankToday > 3.7) {
10 echo "Good work staying hydrated!";
11 if ($havingABadDay)
12 hug();
13}
14else
15 echo "You should drink more water";