❮ PHP Variable Handling Reference
Return the boolean value of different variables:
<?php
echo "0: " .(boolval(0) ? 'true' : 'false') . "<br>";
echo "4: " .(boolval(42) ? 'true' : 'false') . "<br>";
echo '"": ' .(boolval("") ? 'true' : 'false') . "<br>";
echo '"Hello": ' .(boolval("Hello") ? 'true' : 'false') . "<br>";
echo '"0": ' .(boolval("0") ? 'true' : 'false') . "<br>";
echo "[3, 5]: " .(boolval([3, 5]) ? 'true' : 'false') . "<br>";
echo "[]: " .(boolval([]) ? 'true' : 'false') . "<br>";
?>
Try it Yourself »
The boolval() function returns the boolean value of a variable.
boolval(
variable);
Parameter | Description |
---|---|
variable | Required. Specifies the variable to check. Must be a scalar type |
Return Value: | The boolean value of the variable |
---|---|
Return Type: | Boolean |
PHP Version: | 5.5+ |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!