PHP boolval function (PHP 5 >= 5.5.0)

Udemy Generic 728x90

boolval is a php function, added in PHP 5.5 . It returns boolean value of given variable.

Requirement

boolval function is available in PHP 5.5 and  higher version so before using boolval function, please make sure that you are using compatible PHP version .

Syntax

boolval function accepts a variable and returns boolean value against given variable. It has following  syntax -

boolean boolval ( mixed $var) ;

Example


<br />
&lt;?php</p>
<p>    function  getBooleanValue( $var ) {</p>
<p>        if(function_exists('boolval')) {</p>
<p>            $booleanValue = boolval($var);</p>
<p>        } else {</p>
<p>            $booleanValue = &quot;boolval function is not available in current environment , please check your PHP version&quot;;</p>
<p>        }</p>
<p>        return $booleanValue;</p>
<p>    }</p>
<p>    $booleanValue = getBooleanValue( 'Numetric');</p>
<p>    var_dump( $booleanValue);</p>
<p>?&gt;</p>
<p>

 Output

bool(true)

 Source

http://in2.php.net/manual/en/function.boolval.php

Udemy Generic 728x90

Spread the word. Share this post!