PHP boolval() Function

P
PHP debug_zval_dump() Function
PHP flush() Function

In this article, you will learn how to get the boolean value of variables in PHP. The boolval() function in PHP returns the boolean value of a variable.

what is the syntax of the BOOLVAL() function in php?

boolval(variable);

Parameter Description
variable Required. Specify the variable to check. Must be a scalar type

examples of the BOOLVAL() function

Example 1. In this example, we get 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>";
?>
PHP debug_zval_dump() Function
PHP flush() Function

Add comment

Tutor Network

Share this

Learn PHP from A to Z