PHP Tutorial - PHP Boolean

Booleans hold either true or false. Behind the scenes, booleans are integers.

false value


In addition, PHP considers the following values to be false :

  • The literal value false

  • The integer zero (0)

  • The float zero ( 0.0 )

  • An empty string ( " " )

  • The string zero ( "0" )

  • An array with zero elements

  • The special type null (including any unset variables)

  • A SimpleXML object that is created from an empty XML tag


All other values are considered true in a Boolean context.

We can assign true or false value to a boolean type variable.


<?PHP/* w w w . j av a2 s . c o m*/
$bool = true;
print "Bool is set to $booln";
$bool = false;
print "Bool is set to $booln";
?>


The code above generates the following result.


Example 2


In the second if statement we compare the integer value to a boolean value.


<?PHP/* w w w .j a va 2 s . c o 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.

0/Post a Comment/Comments

Previous Post Next Post

Sidebar Ads

Ads1
Ads2