Menu Home

is_bool

osbo.com | PHP | Functions | is_bool

Finds out whether a variable is a boolean

Syntax

is_bool ( mixed $var ) : bool

Parameters

var

The variable being evaluated.

Return

Returns TRUE if var is a boolean, FALSE otherwise.

Examples

1

<?

$var = false;

$return = is_bool($var);

var_dump($var, $return);

?>
bool(false)
bool(true)

2

<?

$vars = array(null, false, true, PHP_INT_MIN, PHP_INT_MAX, 0, 1, 23, -0, +0, -1, +1, -23, +23, 00, 01, 023, 0x0, 0x1, 0x23, 0.0, 1.1, 23.45, 0e10, 1e10, 23e10, "", "0", "1", "23", "-0", "+0", "-1", "+1", "-23", "+23", "00", "01", "023", "0x0", "0x1", "0x23", "0.0", "1.1", "23.45", "0e10", "1e10", "23e10", "0abc", "1abc", "23abc", "-0abc", "+0abc", "-1abc", "+1abc", "-23abc", "+23abc", "00abc", "01abc", "023abc", "0x0abc", "0x1abc", "0x23abc", "0.0abc", "1.1abc", "23.45abc", "0e10abc", "1e10abc", "23e10abc", "abc", "abc0", "abc1", "abc23", "abc-0", "abc+0", "abc-1", "abc+1", "abc-23", "abc+23", "abc00", "abc01", "abc023", "abc0x0", "abc0x1", "abc0x23", "abc0.0", "abc1.1", "abc23.45", "abc0e10", "abc1e10", "abc23e10", array(), array(0, 1));

foreach ($vars as $var) {
    $return = is_bool($var);

    var_dump($var, $return);
    echo PHP_EOL;
}

?>
NULL
bool(false)

bool(false)
bool(true)

bool(true)
bool(true)

int(-9223372036854775808)
bool(false)

int(9223372036854775807)
bool(false)

int(0)
bool(false)

int(1)
bool(false)

int(23)
bool(false)

int(0)
bool(false)

int(0)
bool(false)

int(-1)
bool(false)

int(1)
bool(false)

int(-23)
bool(false)

int(23)
bool(false)

int(0)
bool(false)

int(1)
bool(false)

int(19)
bool(false)

int(0)
bool(false)

int(1)
bool(false)

int(35)
bool(false)

float(0)
bool(false)

float(1.1)
bool(false)

float(23.45)
bool(false)

float(0)
bool(false)

float(10000000000)
bool(false)

float(230000000000)
bool(false)

string(0) ""
bool(false)

string(1) "0"
bool(false)

string(1) "1"
bool(false)

string(2) "23"
bool(false)

string(2) "-0"
bool(false)

string(2) "+0"
bool(false)

string(2) "-1"
bool(false)

string(2) "+1"
bool(false)

string(3) "-23"
bool(false)

string(3) "+23"
bool(false)

string(2) "00"
bool(false)

string(2) "01"
bool(false)

string(3) "023"
bool(false)

string(3) "0x0"
bool(false)

string(3) "0x1"
bool(false)

string(4) "0x23"
bool(false)

string(3) "0.0"
bool(false)

string(3) "1.1"
bool(false)

string(5) "23.45"
bool(false)

string(4) "0e10"
bool(false)

string(4) "1e10"
bool(false)

string(5) "23e10"
bool(false)

string(4) "0abc"
bool(false)

string(4) "1abc"
bool(false)

string(5) "23abc"
bool(false)

string(5) "-0abc"
bool(false)

string(5) "+0abc"
bool(false)

string(5) "-1abc"
bool(false)

string(5) "+1abc"
bool(false)

string(6) "-23abc"
bool(false)

string(6) "+23abc"
bool(false)

string(5) "00abc"
bool(false)

string(5) "01abc"
bool(false)

string(6) "023abc"
bool(false)

string(6) "0x0abc"
bool(false)

string(6) "0x1abc"
bool(false)

string(7) "0x23abc"
bool(false)

string(6) "0.0abc"
bool(false)

string(6) "1.1abc"
bool(false)

string(8) "23.45abc"
bool(false)

string(7) "0e10abc"
bool(false)

string(7) "1e10abc"
bool(false)

string(8) "23e10abc"
bool(false)

string(3) "abc"
bool(false)

string(4) "abc0"
bool(false)

string(4) "abc1"
bool(false)

string(5) "abc23"
bool(false)

string(5) "abc-0"
bool(false)

string(5) "abc+0"
bool(false)

string(5) "abc-1"
bool(false)

string(5) "abc+1"
bool(false)

string(6) "abc-23"
bool(false)

string(6) "abc+23"
bool(false)

string(5) "abc00"
bool(false)

string(5) "abc01"
bool(false)

string(6) "abc023"
bool(false)

string(6) "abc0x0"
bool(false)

string(6) "abc0x1"
bool(false)

string(7) "abc0x23"
bool(false)

string(6) "abc0.0"
bool(false)

string(6) "abc1.1"
bool(false)

string(8) "abc23.45"
bool(false)

string(7) "abc0e10"
bool(false)

string(7) "abc1e10"
bool(false)

string(8) "abc23e10"
bool(false)

array(0) {
}
bool(false)

array(2) {
  [0]=>
  int(0)
  [1]=>
  int(1)
}
bool(false)

PHP