Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

is_bool

Checks whether a value is a boolean.

Syntax

is_bool(mixed $value): bool

Parameters

ParameterTypeDescription
$valuemixedThe value to check.

Return value

bool`true` if the value is `true` or `false`.

Examples

A boolean and look-alikes:

<?php
 
var_dump(is_bool(false));
var_dump(is_bool(0));
var_dump(is_bool('true'));

Output:

bool(true)
bool(false)
bool(false)

Notes

This is how "nothing found" is told apart from a real value: strpos(), for instance, returns false rather than 0.

See also

  • boolval — Converts a value to a boolean.
  • is_null — Checks whether a value is null.
  • gettype — Returns the name of a value's type.

In the tutorial

  • Data types — The main PHP data types — strings, numbers, booleans, arrays and null.

Thanks for reading!

Donate to the site — we work hard for you.