PHP/Data Type/boolean

Материал из Web эксперт
Перейти к: навигация, поиск

Boolean type constant: FALSE

   <source lang="html4strict">

<? if (FALSE)

print("This will never print
");

else

print("This will always print
");

?>

      </source>
   
  


Boolean values

   <source lang="html4strict">

<? $a=100; if($a==100) {

   echo "the variable equals 1!
";

} if($a==true) {

  echo "the variable is true!
";

} ?>


      </source>
   
  


Converting from a boolean to a string will produce a 1 if the boolean is set to true, or an empty string if false.

   <source lang="html4strict">

<?

   $bool = true;
   print "Bool is set to $bool\n";
   $bool = false;
   print "Bool is set to $bool\n";

?>

 </source>
   
  


PHP provides a couple of constants especially for use as Booleans: TRUE and FALSE

   <source lang="html4strict">

<? if (TRUE)

print("This will always print
");

else

print("This will never print
");

?>

      </source>