FILTER_VALIDATE_BOOLEAN constant in PHP

PHPProgrammingServer Side Programming

The FILTER_VALIDATE_BOOLEAN constant validates value as a boolean option.

Return

The FILTER_VALIDATE_BOOLEAN constant returns TRUE for "1", "true", "on" and "yes". It returns FALSE for "0", "false", "off" and "no" otherwise, NULL.

Example

 Live Demo

<?php
   $var="on";
   var_dump(filter_var($var, FILTER_VALIDATE_BOOLEAN));
?>

Output

The following is the output.

bool(true)

Example

Let us see another example.

<?php
   $var="off";
   var_dump(filter_var($var, FILTER_VALIDATE_BOOLEAN));
?>

Output

Here is the output.

bool(false)
raja
Published on 04-Dec-2018 06:50:12
Advertisements