boolval
Description
The boolval of Variable Handling for PHP get the boolean value of a variable.
Syntax
boolval(
mixed $value
): boolParameters
value
The scalar value being converted to a boolean.
Return
The boolean value of value.
Examples
1 · value
<? $value = 0; $return = boolval($value); var_dump($value, $return);
int(0) bool(false)
2 · values
<?
$values =
[
null,
false,
true,
PHP_INT_MIN,
PHP_INT_MAX,
0,
1,
23,
-0,
+0,
-1,
+1,
-23,
+23,
0b0,
0b1,
0o0,
0o1,
0o23,
0x0,
0x1,
0x23,
0.0,
1.1,
23.45,
0e10,
1e10,
23e10,
"",
"0",
"1",
"23",
"-0",
"+0",
"-1",
"+1",
"-23",
"+23",
"0b0",
"0b1",
"0o0",
"0o1",
"0o23",
"0x0",
"0x1",
"0x23",
"0.0",
"1.1",
"23.45",
"0e10",
"1e10",
"23e10",
"0abc",
"1abc",
"23abc",
"-0abc",
"+0abc",
"-1abc",
"+1abc",
"-23abc",
"+23abc",
"0b0abc",
"0b1abc",
"0o0abc",
"0o1abc",
"0o23abc",
"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",
"abc0b0",
"abc0b1",
"abc0o0",
"abc0o1",
"abc0o23",
"abc0x0",
"abc0x1",
"abc0x23",
"abc0.0",
"abc1.1",
"abc23.45",
"abc0e10",
"abc1e10",
"abc23e10",
[],
[0, 1],
new stdclass
];
foreach($values as $value)
{
$return = boolval($value);
var_dump($value, $return);
echo PHP_EOL;
}
NULL
bool(false)
bool(false)
bool(false)
bool(true)
bool(true)
int(-9223372036854775808)
bool(true)
int(9223372036854775807)
bool(true)
int(0)
bool(false)
int(1)
bool(true)
int(23)
bool(true)
int(0)
bool(false)
int(0)
bool(false)
int(-1)
bool(true)
int(1)
bool(true)
int(-23)
bool(true)
int(23)
bool(true)
int(0)
bool(false)
int(1)
bool(true)
int(0)
bool(false)
int(1)
bool(true)
int(19)
bool(true)
int(0)
bool(false)
int(1)
bool(true)
int(35)
bool(true)
float(0)
bool(false)
float(1.1)
bool(true)
float(23.45)
bool(true)
float(0)
bool(false)
float(10000000000)
bool(true)
float(230000000000)
bool(true)
string(0) ""
bool(false)
string(1) "0"
bool(false)
string(1) "1"
bool(true)
string(2) "23"
bool(true)
string(2) "-0"
bool(true)
string(2) "+0"
bool(true)
string(2) "-1"
bool(true)
string(2) "+1"
bool(true)
string(3) "-23"
bool(true)
string(3) "+23"
bool(true)
string(3) "0b0"
bool(true)
string(3) "0b1"
bool(true)
string(3) "0o0"
bool(true)
string(3) "0o1"
bool(true)
string(4) "0o23"
bool(true)
string(3) "0x0"
bool(true)
string(3) "0x1"
bool(true)
string(4) "0x23"
bool(true)
string(3) "0.0"
bool(true)
string(3) "1.1"
bool(true)
string(5) "23.45"
bool(true)
string(4) "0e10"
bool(true)
string(4) "1e10"
bool(true)
string(5) "23e10"
bool(true)
string(4) "0abc"
bool(true)
string(4) "1abc"
bool(true)
string(5) "23abc"
bool(true)
string(5) "-0abc"
bool(true)
string(5) "+0abc"
bool(true)
string(5) "-1abc"
bool(true)
string(5) "+1abc"
bool(true)
string(6) "-23abc"
bool(true)
string(6) "+23abc"
bool(true)
string(6) "0b0abc"
bool(true)
string(6) "0b1abc"
bool(true)
string(6) "0o0abc"
bool(true)
string(6) "0o1abc"
bool(true)
string(7) "0o23abc"
bool(true)
string(6) "0x0abc"
bool(true)
string(6) "0x1abc"
bool(true)
string(7) "0x23abc"
bool(true)
string(6) "0.0abc"
bool(true)
string(6) "1.1abc"
bool(true)
string(8) "23.45abc"
bool(true)
string(7) "0e10abc"
bool(true)
string(7) "1e10abc"
bool(true)
string(8) "23e10abc"
bool(true)
string(3) "abc"
bool(true)
string(4) "abc0"
bool(true)
string(4) "abc1"
bool(true)
string(5) "abc23"
bool(true)
string(5) "abc-0"
bool(true)
string(5) "abc+0"
bool(true)
string(5) "abc-1"
bool(true)
string(5) "abc+1"
bool(true)
string(6) "abc-23"
bool(true)
string(6) "abc+23"
bool(true)
string(6) "abc0b0"
bool(true)
string(6) "abc0b1"
bool(true)
string(6) "abc0o0"
bool(true)
string(6) "abc0o1"
bool(true)
string(7) "abc0o23"
bool(true)
string(6) "abc0x0"
bool(true)
string(6) "abc0x1"
bool(true)
string(7) "abc0x23"
bool(true)
string(6) "abc0.0"
bool(true)
string(6) "abc1.1"
bool(true)
string(8) "abc23.45"
bool(true)
string(7) "abc0e10"
bool(true)
string(7) "abc1e10"
bool(true)
string(8) "abc23e10"
bool(true)
array(0) {
}
bool(false)
array(2) {
[0]=>
int(0)
[1]=>
int(1)
}
bool(true)
object(stdClass)#1 (0) {
}
bool(true)
Links
Related
Variable Handling
- debug_zval_dump
- doubleval
- empty
- floatval
- get_debug_type
- get_defined_vars
- get_resource_id
- get_resource_type
- gettype
- intval
- is_array
- is_bool
- is_callable
- is_countable
- is_double
- is_float
- is_int
- is_integer
- is_iterable
- is_long
- is_null
- is_numeric
- is_object
- is_real
- is_resource
- is_scalar
- is_string
- isset
- print_r
- serialize
- settype
- strval
- unserialize
- unset
- var_dump
- var_export