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.

OperatorNameDescriptionExampleResult
x + yAdditionSum of x and y5 + 510
x – ySubtractionDifference of x and y5 – 23
x * yMultiplicationMultipli of x and y5 * 525
x / yDivisionx Divided by y25 / 55
x % yModulusRemainder of x divided by y25 % 2
10 % 5
17 % 5
1
0
2
– xNegationOpposite of x– 5 
a . bConcatenationConcatenate 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.

AssignmentSame as…Description
x = yx = yThe left operand value set to the value of the expression on the right
x += yx = x + yAddition
x -= yx = x – ySubtraction
x *= yx = x * yMultiplication
x /= yx = x / yDivision
x %= yx = x % yModulus
a .= ba = a . bConcatenate 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.

OperatorNameDescription
++ xPre-incrementFirst increments x by one, then returns value of x
x ++Post-incrementFirst returns value of x, then increments x by one
— xPre-decrementFirst decrements x by one, then returns value of x
x —Post-decrementFirst 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

OperatorNameDescriptionExample
x == yEqualReturn true if x is equal to y5==8 returns false because of both valuse not equals
x === yIdenticalReturn 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 != yNot equalReturn true if x is not equal to y5!=8 returns true because both values not equal
x <> yNot equalreturn true if x is not equal to y5<>8 returns true because both values not equal
x !== yNot identicalReturn 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 > yGreater thanReturn true if x is greater than y5>8 returns false because 5 is less then 8
x < yLess thanReturn true if x is less than y5<8 returns true because here 5 is less then 8.
x >= yGreater than or equal toReturn true if x is greater than or equal to y5>=8 returns false because 5 is not a greater nor equal to 8.
x <= yLess than or equal toReturn true if x is less than or equal to y5<=8 returns true because 5 is less then 8.

Logical Operators

OperatorNameDescriptionExample
x and yAndReturn true if both x and y are true x=6
y=3

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

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

(x==6 xor y==3) returns false
x && yAndReturn true if both x and y are true x=6
y=3
(x < 10 && y > 1) returns true
x || yOrReturn true if either or both x and y are true x=6
y=3
(x==5 || y==5) returns false
! xNotReturn 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.