PHP FILTER_VALIDATE_BOOLEAN Filter
❮ Complete PHP Filter Reference
Definition and Usage
The FILTER_VALIDATE_BOOLEAN filter validates value as a boolean option.
- Name: "boolean"
- ID-number: 258
Possible return values:
- Returns TRUE for "1", "true", "on" and "yes"
- Returns FALSE for "0", "false", "off" and "no"
- Returns NULL on failure if FILTER_NULL_ON_FAILURE is set
Example
<?php
$var1="yes";
$var2="off";
var_dump(filter_var($var1,
FILTER_VALIDATE_BOOLEAN));
echo "<br>";
var_dump(filter_var($var2,
FILTER_VALIDATE_BOOLEAN));
?>
The output of the code will be:
bool(true)
bool(false)
Example
<?php
$var1="Hello";
$var2=23;
var_dump(filter_var($var1,
FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
echo "<br>";
var_dump(filter_var($var2,
FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
?>
The output of the code will be:
NULL
NULL
❮ Complete PHP Filter Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.