boolval
Converts a value to a boolean.
Syntax
boolval(mixed $value): boolParameters
| Parameter | Type | Description |
|---|---|---|
| $value | mixed | Any 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
Related recipes
In the tutorial
- Data types — The main PHP data types — strings, numbers, booleans, arrays and null.