Thursday, 11 March 2021

Php: Booleans

Boolean type represent either true or false.

 

Example

$var1 = true;

$var2 = false;

 

bool_type_demo.php

#!/usr/bin/php

<?php

   $var1 = true;
   $var2 = false;

   echo "\n\$var1 : ";
   var_dump($var1);

   echo "\n\$var2 : ";
   var_dump($var2);
?>

 

Output

$./bool_type_demo.php 


$var1 : bool(true)

$var2 : bool(false)

 

Value of Boolean type variables is case insensitive. for example, TRUE, true, trUE  are all treated as true only.

 

bool_type_1_demo.php

 

#!/usr/bin/php

<?php

   $var1 = true;
   $var2 = TRUE;
   $var3 = trUE;

   $var4 = false;
   $var5 = FALSE;
   $var6 = FAlse;

   echo "\n\$var1 : ";
   var_dump($var1);

   echo "\n\$var2 : ";
   var_dump($var2);

   echo "\n\$var3 : ";
   var_dump($var3);

   echo "\n\$var4 : ";
   var_dump($var4);

   echo "\n\$var5 : ";
   var_dump($var5);

   echo "\n\$var6 : ";
   var_dump($var6);
?>


Output

$./bool_type_1_demo.php 


$var1 : bool(true)

$var2 : bool(true)

$var3 : bool(true)

$var4 : bool(false)

$var5 : bool(false)

$var6 : bool(false)

  

Previous                                                    Next                                                    Home

No comments:

Post a Comment