Finds out whether a variable is a boolean (original) (raw)

is_bool

(PHP 4, PHP 5, PHP 7)

is_bool — Finds out whether a variable is a boolean

Description

is_bool ( mixed $var ) : bool

Finds whether the given variable is a boolean.

Parameters

var

The variable being evaluated.

Return Values

Returns TRUE if var is a boolean,FALSE otherwise.

Examples

Example #1 is_bool() examples

<?php $a = false; <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>b</mi><mo>=</mo><mn>0</mn><mo separator="true">;</mo><mi mathvariant="normal">/</mi><mi mathvariant="normal">/</mi><mi>S</mi><mi>i</mi><mi>n</mi><mi>c</mi><mi>e</mi></mrow><annotation encoding="application/x-tex">b = 0;// Since </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">b</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">0</span><span class="mpunct">;</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord">//</span><span class="mord mathnormal" style="margin-right:0.05764em;">S</span><span class="mord mathnormal">in</span><span class="mord mathnormal">ce</span></span></span></span>a is a boolean, it will return true if (is_bool($a) === true) { echo "Yes, this is a boolean"; }// Since $b is not a boolean, it will return false if (is_bool($b) === false) { echo "No, this is not a boolean"; } ?>

See Also