PHP Operators

PHP Operators Tutorial explain you What are different types of PHP operators and  Examples on implementing PHP operators?

PHP Operators can be separated into the following categories:

  • PHP Arithmetic Operators
  • PHP Assignment Operators
  • PHP Incrementing / Decrementing Operators
  • PHP Comparison Operators
  • PHP Logical Operators
  • PHP Array Operators

PHP Arithmetic Operators

OperatorNameExampleResult
a + b Addition 5 + 4 9
a - b Subtraction 10 – 1 9
a * b Multiplication 3 * 3 9
a / b Division 18 / 2 9
a % b Modulus 20 % 11
8 % 2
9
0
-a Negation -9 -9
a . b Concatenation "Hello"."World" Hello World

PHP Assignment Operators

AssignmentSimilar to …Description
a = b a = b Value of expression on right is assigned to left operand. Here value of 'b' is assigned to operand 'a'.
a += b a = a + b Addition
a -= b a = a - b Subtraction
a *= b a = a * b Multiplication
a /= b a = a / b Division
a %= b a = a % b Modulus
a .= b a = a . b Concatenation

PHP Incrementing / Decrementing Operators

OperatorNameDescription
++a Pre-increment Increments a by 1 and returns a
a++ Post-increment Returns a, then increments by 1
--a Pre-decrement Decrements by 1 and returns a
a-- Post-decrement Returns a, then decrements by 1

PHP Comparison Operators

OperatorNameDescriptionExample
a == b Equal Returns true if a is equal to b 5 == 4 returns false
a === b Identical Returns true if a and b are equal and they are of same type 9 === "9" returns false
a != b
or
a <> b
Not equal Returns true if a is not equal to b 3 != 2
or
3 <> 2
returns true
a !== b Not Identical Returns true if a is not equal to b or they are not of same type 9 !== "9" returns true
a > b Greater than Returns true if a is greater than b 9 > 3 returns true
a < b Less than Returns true if a is less than b 9 < 3 returns false
a >= b Greater than or equal to Returns true if a is greater than or equal to b 9 >= 3 returns true
a <= b Less than or equal to Returns true if a is less than or equal to b 9 <= 3 returns false

PHP Logical Operators

OperatorNameDescriptionExample
a and b
or
a && b
And Returns true if both a and b are true a = 3 b = 9
(a < 5 and b > 4) returns true
or
(a < 5 && b > 10) returns false
a or b
or
a || b
Identical Returns true if either or both a and b are true a = 9 b = 5
(a > 3 or b == 8) returns true
or
(a == 5 || b > 9) returns false
a xor b Xor Returns true if either a or b is true, but not both a = 8 b = 5
(a == 8 xor b == 5) returns false
!a Not Returns true if a is not true a = 9 b = 7
!(a < b) returns true

PHP Array Operators

OperatorNameDescription
a + b Union Union of a and b
a == b Equality Returns true if a and b have same key / value pairs
a === b Identity Returns true if a and b have same key / value pairs in the same order and of the same type
a != b
or
a <> b
Inequality Returns true if a is not equal to b
a !== b Non-identity Returns true if a is not identical to b
   

Online PHP Guide Quiz

You can Check your knowledge by playing the Online PHP Quiz into Various category.

Online PHP Quiz useful to the participants of competitive examinations and quiz programs.

Would you like to test your PHP skills?

   

Search

   

Online PHP Guide Quiz

Would you like to test your PHP skills?

   

Facebook Like Button

   

Follow Us On Google+

 

 

   
Copyright 2012@OnlinePHPGuide.com