Logical operators when evaluated, return a boolean value.i.e true or false. For Example, if x=2 and y=3 then the expression x>y will evaluate to be false. These operators are mostly used in looping and conditional processing. We will very soon learn these topics.
| Operator |
Description |
Example |
| > |
Greater than |
if x=1, x>2 will return false (0) |
| < |
Less than |
if x=1, x<2 will return true (1) |
| >= |
Greater than or Equal to |
if x=1, x>=1 will return true (1) |
| <= |
Less than or Equal to |
if x=1, x<=2 will return true (1) |
| != |
Not Equal to |
if x=1, x!=2 will return true (1) |
The following example will clarify these concepts.
Example
| The PHP Code |
Output of this code |
<?php
$x = 2;
$y = 3;
echo "$x > $y = ".($x>$y)."<br>";
echo "$x<$y\ = ".($x<$y)."<br>";
echo "$x!=$y = ".($x!=$y)."<br>";
echo "$x>=$y = "($x>=$y)."<br>";
?>
|
$x>$y = $x<$y = 1 $x!=$y = 1 $x>=$y =
|
Notice the output of this code. The print function echo does not print null or false values. However it prints the "true" value as 1.