To make it simple for you we
take a expression which will make easier to understand, expression 5 * 5
= 25, here 5 and 25 are the operand and *, = are the php operators.
In PHP there are following type are operators:
Arithmetic operators:In PHP there are following type are operators:
Suppose variable A is 10 and variable B is 5 then:
| Operator | Name | Example | Result |
|---|---|---|---|
| + | Addition | $A + $B | Sum of $A and $B is 15 |
| - | Subtraction | $A – $B | Difference of $A and $B is 5 |
| * | Multiplication | $A * $B | Product of $A and $B is 50 |
| / | Division | $A / $B | Quotient of $A and $B is 0.5 |
| % | Modulus | $A % $B | Remainder of $A divided by $B |
Logical Operators:
Suppose we taking above example, variable A is 10 and variable B is 5 then:
| Operator | Name | Example | Result |
|---|---|---|---|
| and | And | $A and $B | True if both $A and $B are true |
| or | Or | $A or $B | True if either $A or $B is true |
| && | And | $A && $B | True if both $A or $B is true |
| || | Or | $A || $B | True if either $A or $B is true |
| ! | Not | !$A | True if $A is not true |
Comparison Operators:
Suppose variable A is 10 and variable B is 5 then:
| Operator | Name | Example | Result |
|---|---|---|---|
| == | Equal | $A == $B | True if $A is equal to $B |
| != | Not equal | $A != $B | True if $A is not equal to $B |
| > | Greater than | $A > $B | True if $A is greater than $B |
| < | Less than | $A < $B | True if $A is less than $B |
| >= | Greater than or equal to | $A >= $B | True if $A is greater than or equal to $B |
| <= | Less than or equal to | $A <= $B | True if $A is less than or equal to $B |
Assignment Operator:
This operator is used to write the value to a variable.
| Operator | Name | Example |
|---|---|---|
| = | Equal | A=B |
| += | Addition | C= A+B |
| -= | Subtraction | C= A-B |
| *= | Multiplication | C= A*B |
| /= | Division | C= A/B |
| %= | Modulus | C= A%B |
Conditional Operator:
There is one other kind of php operators tutorial called conditional operator.It is also called ternary operator.It first
evaluates an expression for a true or false value and then execute one
statement between the two given statements depending upon the result of
the evaluation, condition operator woks as follows:
- The first operand is implicitly converted to bool. It is evaluated and all side effects are completed before continuing.
- If the first operand evaluates to true, the second operand is evaluated.
- If the first operand evaluates to false, the third operand is evaluated.
 :
No comments:
Post a Comment