MY mENU


Monday 26 March 2012

Operators in PHP


The most common PHP operators are 
  1. Assignment operators,
  2. Arithmetic operators, 
  3. combined operators, 
  4. comparison operators, 
  5. logical operators. 
  6. Relational Operators
  7. Increment and Decrement Operator
  8. Negation Operator
  9. Error Controlling operator
  10. String/Concatenation operator
  11. Conditional(or) Ternary Operator
  12. "new" Operator
  13. "instanceOf" operator
  14. Scope resolution operator
  15. Dereferencing operator


Assignment Operators
The basic assignment operator in PHP is "=". This means that the operand to the left of "=" gets set to the value to the right of "=".

Arithmetic Operators

OperatorExampleResult
+4 + 26
-4 - 22
*4 * 28
/4 / 22
%4 % 20
++x = 4; x++;x = 5
--x = 4; x--;x = 3



Combined Operators
You can combine an arithmetic operator with the assignment operator to form a combined operator. Combined operators are shown below:

OperatorExampleMeaning
+=y += xy = y + x
-=y -= xy = y - x
*=y *= xy = y * x
/=y /= xy = y / x
%=y %= xy = y % x


Comparison Operators

OperatorMeaning
==is equal to
!=is not equal to
>is greater than
>=is greater than or equal to
<is less than
<=is less than or equal to


Logical Operators

OperatorMeaning
||or
&&and
andand
oror
xorxor
!not



Relational Operators
= = = will check for the content and also for the type.
! = =  


Increment and Decrement Operator


++ and - -


Negation Operator


- multiplying with (-1)


Error Controlling Operator:


@   when prepended an expression, any warning messages that is being generated will gets suppressed.


A PHP application is associated with two types of runtime mistakes:

  • Warning - if  warning occurs, the rest of the Programme  will be executed.
  • A Fatal error - if a fatal error occurs the Programme gets terminated.
String/concatenation operators:

. or .=

Conditional / ternery operator:   ?:



No comments:

Post a Comment