PHP Boolean Data Type:
Boolean is one of the simplest data type supported by PHP. A boolean is used to express a truth value either true or false.
For conversion to boolean data type, we need to use (bool) or (boolean) casts. Though it is not necessary because whenever we need to get a boolean value from an operator, function or control structure requires a boolean value, it automatically converts.
Example of PHP Boolean Data Type :
<?php
$a
=23;var_dump ((boolean)(
$a));echo"<br/>";$a
=23.23;var_dump ((boolean)(
$a));echo"<br/>";$a
=0.0;var_dump ((boolean)(
$a));echo"<br/>";$a
=-12;var_dump ((boolean)(
$a));echo"<br/>";$a
;var_dump ((boolean)(
$a));echo"<br/>";$a
=NULL;var_dump ((boolean)(
$a));echo"<br/>";$a
=0;var_dump ((boolean)(
$a));echo"<br/>";$a
='Hello';var_dump ((boolean)(
$a));echo"<br/>";$a
='a';var_dump ((boolean)(
$a));echo"<br/>";$a
=(array(1,2));var_dump ((boolean)(
$a));echo"<br/>";$a
=(array());var_dump ((boolean)(
$a));echo"<br/>";$a
=("");var_dump ((boolean)(
$a));echo"<br/>";?>
Output:
bool(true)
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.