Next Chapter
CHAPTER-4 PHP Operators
PHP supports the following operators. Their usage is just like in any other programming language like C, C++ etc.
Arithmetic operators:-
Operator | Description | Example |
+ | Addition | 9+5=14 |
- | Subtraction | 9-5=4 |
* | Multiplication | 9*5=45 |
/ | Division | 10/5=2 |
% | Modulus(Remainder of a/b) | 9%5=4 |
++ | Increment | i=4; i++ which results in i=5 |
-- | Decrement | i=4; i-- which results in i=3 |
Assignment Operators:-
Operator | Example |
= | $val=5; |
+= | $val+=6; which results in $val=11(5+6) |
-= | $val-=3; which results in $val=2(5-3) |
*= | Similar to += and -= |
/= | Similar to += and -= |
.= | $str=”ab”; $str.=”cd”; results in $str=’abcd” |
%= | Similar to += and -= |
Comparison Operators:-
Operator | Description | Example |
== | Equal To | 5==5 is true and 5==3 is false |
!= | Not Equal To | 5!=5 is false and 5!=3 is true |
<> | Not Equal To | 5<>5 is false and 5<>3 is true |
> | Greater Than | 5>3 is true and 3>5 is false |
< | Less Than | 5<3 is false and 3<5 is true |
>= | Greater Than or Equal To | 5>=5 is true and 5>5 is false |
<= | Less Than or Equal To | 5<=5 is true and 5<5 is false |
Logical Operators:-
Operator | Description | Example |
&& | AND | true && false is false |
|| | OR | true || false is true |
! | NOT | NOT true is false |
I am not presenting a separate example to show the use of the above mentioned operators. Their usage is pretty much obvious. But, if you don’t understand any one of them then don’t worry about it now. You will understand as you go on with the tutorial.
Next Chapter
No comments:
Post a Comment