How to validate value is Boolean in Php?
In this post, This function checks whether a variable is of type boolean or not.
1. Code:
<?php function checkTheValueIsBoolean($var){ return filter_var($var, FILTER_VALIDATE_BOOLEAN); } var_dump(checkTheValueIsBoolean("off")); echo "<br>"; var_dump(checkTheValueIsBoolean("on")); ?>
2. Example:
Input:
input: "off" Input: "on" input: "a"
Output:
output: true output: true output: false