HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

boolval

Description

The boolval of Variable Handling for PHP get the boolean value of a variable.

Syntax

boolval(
    mixed $value
): bool

Parameters

value

The scalar value being converted to a boolean.

Return

The boolean value of value.

Examples

1

<?

$value = 0;

$return = boolval($value);

var_dump($value, $return);
int(0)
bool(false)

2

<?

$values = [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), 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(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(2) "00"
bool(true)

string(2) "01"
bool(true)

string(3) "023"
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(5) "00abc"
bool(true)

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

string(6) "023abc"
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(5) "abc00"
bool(true)

string(5) "abc01"
bool(true)

string(6) "abc023"
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)