Consider the following simple program that prints two Boolean variables.
/********************************************************************************/
<html>
<head>
<title>Booleans</title>
</head>
<body>
<?php
$var1=true;
$var2=false;
echo
"true = ".$var1."<br />";
echo
"false = ".$var2."<br />";
?>
</body>
</html>
/********************************************************************************/
Output:-
true = 1
false =
false =
Note that a false value is not printed in the browser.
Now let's consider some of the boolean functions that determines whether a variable is set to any value or not.
Source Code # 2
/********************************************************************************/
<html>
<head>
<title>Boolean Functions</title>
</head>
<body>
<?php
$var1=5;
/*
if a value is assigned then isset() returns 1 otherwise 0 */
echo
"isset var1 = ".isset($var1)."<br />";
echo
"isset var2 = ".isset($var2)."<br />";
unset($var1);
echo
"isset var1 after unsetting var 1 = ".isset($var1)."<br
/>";
$var1=45;
echo
"is var1 empty = ".empty($var1)."<br />";
echo
"is var2 empty= ".empty($var2)."<br />";
?>
</body>
</html>
/*******************************************************************************/
Output:-
isset var1 = 1
isset var2 =
isset var1 after unsetting var 1 =
is var1 empty =
is var2 empty= 1
isset var2 =
isset var1 after unsetting var 1 =
is var1 empty =
is var2 empty= 1
No comments:
Post a Comment