Latest web development tutorials

PHP FILTER_VALIDATE_BOOLEANT filter

PHP Filter Reference Complete PHP Filter Reference

Definition and Usage

FILTER_VALIDATE_BOOLEAN the filter value as a boolean option to verify.

  • Name: "boolean"
  • ID-number: 258

The possible return values:

  • If it is "1", "true", "on" and "yes", then returns TRUE.
  • If it is "0", "false", "off" and "no", it returns FALSE.
  • Otherwise, it returns NULL.

Examples

<?php
$var="yes";

var_dump(filter_var($var, FILTER_VALIDATE_BOOLEAN));
?>

Output code is as follows:

bool(true)


PHP Filter Reference Complete PHP Filter Reference