Booleans hold either true or false. Behind the scenes, booleans are integers.
In addition, PHP considers the following values to be false
:
All other values are considered true in a Boolean context.
We can assign true or false value to a boolean type variable.
<?PHP
$bool = true;
print "Bool is set to $bool\n";
$bool = false;
print "Bool is set to $bool\n";
?>
The code above generates the following result.
In the second if statement we compare the integer value to a boolean value.
<?PHP/* w ww . j a va 2s . co m*/
$a=100;
if($a==100) {
echo "the variable equals 1!\n";
}
if($a==true) {
echo "the variable is true!";
}
?>
The code above generates the following result.