Logical Operators allow your script to determine the status of conditions (such as the comparisons in the preceding section). In the context of if…else or while statements, logical operators execute certain code based on which conditions are true and which are false.
For now, focus on the && (and) and || (or) operators to determine the validity of a few comparisons.
For now, focus on the && (and) and || (or) operators to determine the validity of a few comparisons.
Example:
<HTML>
<HEAD>
<TITLE>Using Logical Operators</TITLE>
</HEAD>
<BODY>
<?
$degrees = “95”;
$hot = “yes”;
echo statements will print:
if (($degrees > 100) || ($hot == “yes”)) {
echo “<P>TEST 1: It’s <strong>really</strong> hot!</P>”;
} else {
echo “<P>TEST 1: It’s bearable.</P>”;
}
if (($degrees > 100) && ($hot == “yes”)) {
echo “<P>TEST 2: It’s <strong>really</strong> hot!</P>”;
} else {
echo “<P> TEST 2: It’s bearable.</P>”;
}
?>
</BODY>
</HTML>