PHP Operators

PHP Operators OR What is Operators in PHP

PHP Operators are symbols that tell the PHP processor to perform specific oration. For example, the addition (+) symbol is an operator that tells PHP to add two variables or values, while the greater-than (>) symbol is an operator that tells PHP to compare two values.

PHP language supports following type of operators.

  1. Arithmetic Operators
  2. Assignment Operators
  3. Incrementing/Decrementing Operators
  4. Comparison Operators
  5. Logical Operators

Arithmetic Operators

Arithmetic operators use to perform all kind of airthmetic operations, such as Addition, Subtraction, Multiplication, Division etc.

Operator Name Description Example Result
x + y Addition Sum of x and y 5 + 5 10
x – y Subtraction Difference of x and y 5 – 2 3
x * y Multiplication Multipli of x and y 5 * 5 25
x / y Division x Divided by y 25 / 5 5
x % y Modulus Remainder of x divided by y 25 % 2
10 % 5
17 % 5
1
0
2
– x Negation Opposite of x – 5  
a . b Concatenation Concatenate two strings “Hi” . “Hello” HiHello

Assignment Operators

The basic assignment operator in PHP is “=”. It means that the left operand
value set to the value of the expression on the right. That is, the value of “$x
= 5” is 5.

Assignment Same as… Description
x = y x = y The left operand value set to the value of the expression on the right
x += y x = x + y Addition
x -= y x = x – y Subtraction
x *= y x = x * y Multiplication
x /= y x = x / y Division
x %= y x = x % y Modulus
a .= b a = a . b Concatenate two strings

Incrementing/Decrementing Operators

The basic Incrementing/Decrementing Operators in PHP is use to increse or decrese value of operand by one, performing this operator we use (” ++ or — “) Signe.

Operator Name Description
++ x Pre-increment First increments x by one, then returns value of x
x ++ Post-increment First returns value of x, then increments x by one
— x Pre-decrement First decrements x by one, then returns value of x
x — Post-decrement First returns value of x, then decrements x by one

Comparison Operators

Basicaly Comparison operators use to compare two values such as ” x==y “. mostaly comparison operators are use in conditions statement

Operator Name Description Example
x == y Equal Return true if x is equal to y 5==8 returns false because of both valuse not equals
x === y Identical Return true if x is equal to y, and they are of same type of datatype. 5===”5″ returns false because second valuse is a string and first is int.
x != y Not equal Return true if x is not equal to y 5!=8 returns true because both values not equal
x <> y Not equal return true if x is not equal to y 5<>8 returns true because both values not equal
x !== y Not identical Return true if x is not equal to y, or they are not of same type of datatype. 5!==”5″ returns true because both values or thier datatype not equal.
x > y Greater than Return true if x is greater than y 5>8 returns false because 5 is less then 8
x < y Less than Return true if x is less than y 5<8 returns true because here 5 is less then 8.
x >= y Greater than or equal to Return true if x is greater than or equal to y 5>=8 returns false because 5 is not a greater nor equal to 8.
x <= y Less than or equal to Return true if x is less than or equal to y 5<=8 returns true because 5 is less then 8.

Logical Operators

Operator Name Description Example
x and y And Return true if both x and y are true x=6
y=3

(x < 10 and y > 1) returns true
x or y Or Return true if either or both x and y are true x=6
y=3

(x==6 or y==5) returns true
x xor y Xor Return true if either x or y is true, but not both x=6
y=3

(x==6 xor y==3) returns false
x && y And Return true if both x and y are true x=6
y=3
(x < 10 && y > 1) returns true
x || y Or Return true if either or both x and y are true x=6
y=3
(x==5 || y==5) returns false
! x Not Return true if x is not true x=6
y=3
!(x==y) returns true

Tools:

Crypto Currency

PHPKIDA provides free online the best real-time crypto market price, news, predictions, index with graphs & historical data for 2000+ coins including bitcoin, ethereum, & altcoins from major cryptocurrency exchanges.

Visite Tool

Icon Generator

PHPKIDA provides free online icon generator. Our icon generator help you to edit, modify, resize and customize icon for your website and applications. Convert to a shap you like add icon border, you can change icon border color, border size, background color, icon shadow, icons color, icon size in your own way and save it as a png image.

Visite Tool

Youtube Video Downloader

PHPKIDA provides Free online YouTube video downloader to download YouTube videos quickly in MP4, 3GP, and more. Search your video and free fast download youtube videos.

Visite Tool

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.