Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

boolval

Converts a value to a boolean.

Syntax

boolval(mixed $value): bool

Parameters

ParameterTypeDescription
$valuemixedAny value.

Return value

bool`false` for `0`, `''`, `'0'`, `[]`, `null`; otherwise `true`.

Examples

What counts as false:

<?php
 
var_dump(boolval('0'));
var_dump(boolval('false'));
var_dump(boolval([]));

Output:

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

Notes

The string 'false' is truthy: it is not empty. To parse words like "true", "yes", "on" use filter_var($value, FILTER_VALIDATE_BOOLEAN).

See also

  • intval — Converts a value to an integer.
  • strval — Converts a value to a string.
  • empty — Checks that a variable does not exist or holds an "empty" value.

Related recipes

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.