Validate value as a boolean option in PHP

Description

The following code shows how to validate value as a boolean option.

Example


/*from w  ww .j a  v a  2s .  co  m*/

<?php
    $var="yes";

    var_dump(filter_var($var, FILTER_VALIDATE_BOOLEAN));

/*
  Possible return values:

  Returns TRUE for "1", "true", "on" and "yes"
  Returns FALSE for "0", "false", "off" and "no"
  Returns NULL otherwise.

*/
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone