PHP Operators
Not only in PHP generally the operators are used to operate on values.There are a variety of operators are available in this section.
Arithmetic operators:
s.no operator Description Example Results
1. + Addition X=2 4
X+2
2. - Subtraction X=2
5-X 3
3. * Multiplication X=2
X*5 10
4. / Division X=15
X/5 3
5. % Modulus X=5
X/2 1
6. ++ Increment X=10 11
X++
7. -- Decrement X=10 9
X--
Assignment operators:
s.no operator Example Results
1. = x=y x=y
2. += x+=y x=x+y
3. -= x-=y x=x-y
4. *= x*=y x=x*y
5. /= x/=y x=x/y
6. %= x%=y x=x%y
Comparison operators:
s.no operator Explanation Results
1. = = is equal to 10 = = 10 retuns the false statement
2. != is not equal to 10!=20 returns the true statement
3. > is greater than 10 > 20 returns the false statement
4. < is less than 10 < 20 returns the true statement
5. >= is greater than or
equal to 10>=20 returns false
6. <= is less than or 10<=20 returns true
equal to
1. = = is equal to 10 = = 10 retuns the false statement
2. != is not equal to 10!=20 returns the true statement
3. > is greater than 10 > 20 returns the false statement
4. < is less than 10 < 20 returns the true statement
5. >= is greater than or
equal to 10>=20 returns false
6. <= is less than or 10<=20 returns true
equal to
Logical operators:
s.no operator Description Results
1. && And x=7
y=4
y=4
(x < 10 && y > 1) retuns true
2. || OR (x = = 5 || y = = 5) returns false
3. ! NOT x=7
2. || OR (x = = 5 || y = = 5) returns false
3. ! NOT x=7
y=4
!(x= = y) returns true
No comments:
Post a Comment