downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

debug_zval_dump> <Variable handling Functions
[edit] Last updated: Fri, 26 Apr 2013

view this page in

boolval

(PHP 5 >= 5.5.0)

boolvalGet the boolean value of a variable

Description

boolean boolval ( mixed $var )

Returns the boolean value of var.

Parameters

var

The scalar value being converted to a boolean.

Return Values

The boolean value of var.

Examples

Example #1 boolval() examples

<?php
echo '0:        '.(boolval(0) ? 'true' 'false')."\n";
echo 
'42:       '.(boolval(42) ? 'true' 'false')."\n";
echo 
'0.0:      '.(boolval(0.0) ? 'true' 'false')."\n";
echo 
'4.2:      '.(boolval(4.2) ? 'true' 'false')."\n";
echo 
'"":       '.(boolval("") ? 'true' 'false')."\n";
echo 
'"string": '.(boolval("string") ? 'true' 'false')."\n";
echo 
'[1, 2]:   '.(boolval([12]) ? 'true' 'false')."\n";
echo 
'[]:       '.(boolval([]) ? 'true' 'false')."\n";
echo 
'stdClass: '.(boolval(new stdClass) ? 'true' 'false')."\n";
?>

The above example will output:

0:        false
42:       true
0.0:      false
4.2:      true
"":       false
"string": true
[1, 2]:   true
[]:       false
stdClass: true

See Also



add a note add a note User Contributed Notes boolval - [1 notes]
up
-3
info at lomalkin dot ru
1 month ago
<?

// Hack for old php versions to use boolval()

if (!function_exists('boolval')) {
        function boolval($val) {
                return (bool) $val;
        }
}
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites