boolval()

boolval() — Get the boolean value of a variable.

Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.5.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

boolval(mixed $value): bool

Parameters

ParameterTypeWhat it takes
$valuemixedThe scalar value being converted to a bool.

Return value

The bool value of value.

Example

A runnable snippet:

echo '0: '.(boolval(0) ? 'true' : 'false')."\n"; echo '42: '.(boolval(42) ? 'true' : 'false')."\n"; echo '0.0: '.(boolval(0.0) ? 'true' : 'false')."\n"; echo '4.2: '.(boolval(4.2) ? 'true' : 'false')."\n"; echo '"": '.(boolval("") ? 'true' : 'false')."\n"; echo '"string": '.(boolval("string") ? 'true' : 'false')."\n"; echo '"0": '.(boolval("0") ? 'true' : 'false')."\n"; echo '"1": '.(boolval("1") ? 'true' : 'false')."\n"; echo '[1, 2]: '.(boolval([1, 2]) ? 'true' : 'false')."\n"; echo '[]: '.(boolval([]) ? 'true' : 'false')."\n"; echo 'stdClass: '.(boolval(new stdClass) ? 'true' : 'false')."\n";

Output:

0: false 42: true 0.0: false 4.2: true "": false "string": true "0": false "1": true [1, 2]: true []: false stdClass: true

See also

floatval(), intval(), strval(), settype(), is_bool()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page boolval() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.