2. PHP Operators


1.     Commonly Used Arithmetic Operators
                <?php
$n1=5;
$n2=2;
            $SUM=$n1+$n2;
            $DIFF=$n1-$n2;
            $PRODUCT=$n1*$n2;
            $QUOTIENT=$n1/$n2;
            $REMAINDER=$n1%$n2;
?>

2.     Relational Operators
==Equal to (the same as)
!=Not equal to (not the same as)
> Greater than (more, bigger, larger, higher, longer than, exceeds, over
< Less than (smaller, fewer, lower, shorter than, below)
>=Greater than or equal to (at least)
<=Less than or equal to (at most)
Example:
<?php           
                        $a=5;$b=3;
                        echo $a==$b;
                        echo $a!=$b;
                        echo $a>$b;
                        echo $a<$b;
                        echo $a>=$b;
                        echo $a<=$b;
?>

3.     Logical Operators
•       ! (NOT) Negation (Priority -1)                                             
•       && (AND) Logical Multiplication  (Priority -2)  
•       || (OR)Logical Addition (Priority -3)
Example:
                <?php
                                $a=5;$b=3;
                                echo !($a==$b);
                                echo $a>$b && $a<=$b;
                                echo $a<$b || $a>=$b;
                 ?> 

No comments:

Post a Comment