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

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Free online tool to download Instagram videos, photos and save Instagram videos, photos to your device. It's free & easy to use.

Download Now

CURRENCY CONVERTER

Our real time currency converter calculator will convert your money based on current values from around the world. It's free & easy to use.

Convert Now

ROBOST.TXT GEN.

Create robots txt file that help search engines to crawling and indexing your site with help of our free online Robots.txt Generator tool.

Create Now

HTML MINIFIER

Free online tool to minify or compress html code and reduce the size of html code in few clicks. It's free & easy to use.

Minify Now

CSS MINIFIER

Free online tool to minify or compress css code and reduce the size of css code in few clicks. It's free & easy to use.

Minify Now

JAVASCRIPT MINIFIER

Free online tool to minify or compress javascript code and reduce the size of javascript code in few clicks. It's free & easy to use.

Minify Now

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.