PHP FILTER_VALIDATE_BOOLEANFilter


PHP Filter 参考手册Complete PHP Filter Reference

Definition and Usage

The FILTER_VALIDATE_BOOLEAN filter validates a value as a boolean option.

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

Possible return values:

  • Returns TRUE if "1", "true", "on" and "yes".
  • Returns FALSE if "0", "false", "off" and "no".
  • Otherwise returns NULL.

Examples

<?php
$var="yes";

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

The output of the code looks like this:

bool(true)


PHP Filter 参考手册Complete PHP Filter Reference Other Extensions