Articles → PHP → Operators in PHP

# Operators in PHP

## Arithmetic operators

 Operator Name Description + Add Sum of 2 operand (left operand + right operand) - Subtract Difference of 2 operands (left operand – right operand) * Multiply Product of 2 operands (left operand * right operand) / Division Quotient of 2 operands (left operand / right operand) % Modulus Remainder of division when one operand is divided by other - Operand Negation Opposite of operand . Concatenation Combine 2 strings into one.

```<?PHP
echo "Addition","\n", 1 + 2, "<br>";
echo "Subtract","\n", 2 - 1, "<br>";
echo "Multiplication","\n", 2 * 3, "<br>";
echo "Division","\n", 4 * 2, "<br>";
echo "Modulus","\n", 5 % 3, "<br>";
echo "Negation","\n", -3, "<br>";
echo "Concatenation","\n", "wel"."come", "<br>";
?>```

## Assignment operators

 Operators How they are used a = b a = b a += b a = a + b a -= b a = a + b a *= b a = a * b a /= b a = a / b a %= b a = a % b

```<?php

\$a = 1;
\$b = 2;

\$a = \$b;
echo \$a,"\n";

\$a += \$b;
echo \$a,"\n";

\$a -= \$b;
echo \$a,"\n";

\$a *= \$b;
echo \$a,"\n";

\$a /= \$b;
echo \$a,"\n";

\$a %= \$b;
echo \$a,"\n";
?>```

## Incrementing/Decrementing operators

 Operators Description ++x This operator increments the value of variable by one and then returns it. x++ This operator returns the variable and then increments it by one. --y This operator decrements the value of variable by one and then returns it. y-- This operator returns the variable and then decrements it by one.

```<?php
\$var = 4;
echo ++\$var;
echo \$var++;
echo --\$var;

echo \$var--;
?>```

## Comparison operators

 Operators Description a == b Checks if value of a is equal to value of b even if data type is different then this expression returns true else returns false. a === b Checks if value of a is equal to value of b and data type of both the operands are same then this expression returns true else false a != b Or a <> b If value of a is not equal to value of b then this expression returns true else false. a !== b If value of a is not equal to value of b or data type of a is not equal to data type of b then this expression returns true else false. a > b If value of a is greater than value of b then this expression returns true else false. a < b If value of a is greater than or equal to value of b then this expression returns true else false. a >= b If value of a is less than or equal to value of b then this expression returns true else false. a <= b This operator decrements the value of variable by one and then returns it.

## Logical Operators

 Operators Name Description x and y / x && y And True of both x and y are true x or y / x || y Or True if either one or both is true x xor y Xor True if either one is true but not both !x Not True if x is not true

 Posted By  - Karan Gupta Posted On  - Sunday, May 19, 2013

Query/Feedback

 Your Email Id Subject Query/Feedback Characters remaining 250