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

Operator Name Example Result
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

Assignment Similar 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

Operator Name Description
++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

Operator Name Description Example
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

Operator Name Description Example
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

Operator Name Description
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
SHARE
Previous articlePHP String Variables
Next articlePHP If Else Statement
I am a young Information Systems Security Engineer(CEH). I had started with penetration testing when i am 17 years old. It all started with Kali linux and Metasploit.In free time i will play with Security holes/Bug bounty/Pentesting and Hacking !!!