FILTER_VALIDATE_BOOLEAN constant in PHP


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)

Updated on: 27-Dec-2019

206 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements