BOOLVAL(3) 1 BOOLVAL(3)
boolval - Get the boolean value of a variable
SYNOPSIS
boolean boolval (mixed $var)
DESCRIPTION
Returns the boolean value of $var.
PARAMETERS
o $var
- The scalar value being converted to a boolean.
RETURN VALUES
The boolean value of $var.
EXAMPLES
Example #1
boolval(3) examples
<?php
echo '0: '.(boolval(0) ? 'true' : 'false')."
";
echo '42: '.(boolval(42) ? 'true' : 'false')."
";
echo '0.0: '.(boolval(0.0) ? 'true' : 'false')."
";
echo '4.2: '.(boolval(4.2) ? 'true' : 'false')."
";
echo '"": '.(boolval("") ? 'true' : 'false')."
";
echo '"string": '.(boolval("string") ? 'true' : 'false')."
";
echo '"0": '.(boolval("0") ? 'true' : 'false')."
";
echo '"1": '.(boolval("1") ? 'true' : 'false')."
";
echo '[1, 2]: '.(boolval([1, 2]) ? 'true' : 'false')."
";
echo '[]: '.(boolval([]) ? 'true' : 'false')."
";
echo 'stdClass: '.(boolval(new stdClass) ? 'true' : 'false')."
";
?>
The above example will 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(3), intval(3), strval(3), settype(3), is_bool(3), Type juggling.
PHP Documentation Group BOOLVAL(3)