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.
?>
$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.
?>
All PHP Scripts on this website are provided by phpscripts4u.com where you can find all the latest PHP code snippets, plugins and libraries.