Delivered by GET EMAIL UPDATES FeedBurner
We always respect your privacy and take protecting it seriously.
We won't Spam You

PHP Operators

, 0,
PHP Operators
There is an operator in any programming language. It is very important to learn these operators which are used continuously. You should learn them if you sit for Marketplace like Upwork, Elance or Zend etc. There are many questions in the examination the topic of the operator which is not usually used. Anyway we are showing you all.
Operator: For example $x + $y; Here $x + $y these are Operand and plus (+) stain is operator. There are many kinds of operators such as +, -, *, /, !, ++, --, ||, and etc. Many operators just worked with an operand like ++(increment operator) or ! (not operator) etc. This is called Unary operator.
There are many operators which are worked in two operand like +(Addition or Plus operator) or –( Subtraction or minus operator) etc. Understandingly these operators are Binary operator. Bulk operators are Binary operator.
There are many operators which are worked in three operand like ? : . Understandingly these operators are Tenary operator. There is only one Tenary operator.

There are some kinds of operator, such as---
Arithmetic operator:
Do you remember the mathematics of pimping time? To do the mathematics you must used the stain like Addition or Plus (+),Subtraction (-),Multiplication(x), Division . Now there use are same here----
ExampleName of operatorExplain
-$xNegationThe opposite of $x
$x + $yAdditionAddition between $x and $y
$x - $ySubtractionSubtraction between $x to $y
$x * $yMultiplicationMultiplication between $x and $y
$x / $yDivisionDivision between $x and $y
$x % $yModulusResidue after Division between $x and $y
$x ** $yExponentiationIt is not use extensively in the version of PHP 5.6

$x = 20;$y = 5;
echo 'Negation of $x : '. (-$x).'<br/>';
echo 'Addition of $x and $y : '. ($x + $y).'<br/>';
echo 'Subtraction of $y from $x : '. ($x - $y).'<br/>';
echo 'Multiplication of $x and $y : '. ($x * $y).'<br/>';
echo 'Division of $x by $y : '. ($x/$y).'<br/>';
echo 'Remainder of $x divided by $y : '. ($x % $y);

Negation of $x : -20
Addition of $x and $y : 25
Subtraction of $y from $x : 15
Multiplication of $x and $y : 100
Division of $x by $y : 4
Remainder of $x divided by $y : 0

Before solve the modulus make two operands as integer (if decimal tends). Then it solve modulus. And divisible mark is the result mark. Such as-----
If it is $x = -20 and $y = 5 so that the result of ($x%$y) is -5.
**The operation come first because of the first bracket and then the concat come with sting. The result is fault if the bracket is ejected.
** The meaning of $x = 20 that means 20. So, if it is $y = ($x = 20) + 5; than the result of $y or output operator is 25 because it becomes $y = 20+5 now.
Assignment operator:
Assignment operator is normally equal stain. With this operator there are some assignment operator which is called Combined Operator. There are some example are given bellow:
// 20 assigned to $x (assignment operator)
$x = 20;

// combined operator +=
$x += 20; /* this means $x = $x + 20*/
echo $x .'<br/>';

//combined operator .=
$y = 'PHPAns Basic';
$y .= ' PHP Tutorials'; /* this means $y = $y . ' Tutorials'*/
echo $y;

PHPAns Basic PHP Tutorials

$x = 20 means that the value of $x impute 20. Or you would say that it is impute from right expation to left operand.
Now there is given $x += 20; In output the of $x += 20 is 40 and accorded to $y = ' PHP Tutorials'; in output we are seeing that it comes PHPAns Basic Tutorials. Here the operator of += and .= is given than the main variable encroached the next one. In technical language it is called assignment by value.
Assignment by reference:
The using of PHP and stain the same value of two variables alters in assign.
// assignment by reference
$x = 20;
$y = &$x;

echo $x.'<br/>';
echo $y;


Because of assignment by value the value of main variable is copy to next variable. If you do it by assignment by reference it is not the previous one. Now if we change the value of $x then the value of $y is changed such as
// assignment by reference
$x = 20;
$y = &$x;

$x = 4;
echo $x.'<br/>';
echo $y;


See, the $y is changed cause $y is referance to $x.

In next article we will learn about,
  • php bitwise operators
  • php logical operators
  • php operators precedence

Download PDF
Signup & Get $25 Free
Is this article helpful for you?


  • Connect
Create an free account and start learning & sharing! Sign Up