note 80648 modified in language.types.boolean by danbrown
| From: | danbrown@php.net | Date: | Thu, 18 Jun 2009 14:11:03 +0000 |
| Subject: | note 80648 modified in language.types.boolean by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-157079@lists.php.net to get a copy of this message | ||
It is correct that TRUE or FALSE should not be used as constants for the numbers 0 and 1. But there
may be times when it might be helpful to see the value of the Boolean as a 1 or 0. Here's how
to do it.
<?php
$var1 = TRUE;
$var2 = FALSE;
echo $var1; // Will display the number 1
echo $var2; //Will display nothing
/* To get it to display the number 0 for
a false value you have to typecast it: */
echo (int)$var2; //This will display the number 0 for false.
?>
--was--
It is correct that TRUE or FALSE should not be used as constants for the numbers 0 and 1. But there
may be times when it might be helpful to see the value of the Boolean as a 1 or 0. Here's how
to do it.
$var1 = TRUE;
$var2 = FALSE;
echo $var1; // Will display the number 1
echo $var2; //Will display nothing
To get it to display the number 0 for a false value you have to typecast it:
echo (int)$var2; //This will display the number 0 for false.
http://php.net/manual/en/language.types.boolean.php