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 Up work, 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 operands like +(Addition or Plus operator) or –( Subtraction or minus operator) etc. Understandingly these operators are a Binary operator. Bulk operators are the Binary operator.
There are many operators which are worked in three operands like? : . Understandingly these operators are a Tenary operator. There is only one Ternary 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 use the stain like Addition or Plus (+), Subtraction (-), Multiplication(x), Division. Now there use are same here-

``<?php\$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);?>``
Output:
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 solving the modulus make two operands as the integer (if decimal tends). Then it solves modulus. And divisible mark is the resulting 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 concert come with a sting. The result is the 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:
The assignment operator is normally equal stain. With this operator, there is some assignment operator which is called Combined Operator. There is some example are given bellow:

``<?php// 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;?>``

Output

40
PHPAns Basic PHP Tutorials

\$x = 20 means that the value of \$x impute 20. Or you would say that it is imputed from right expansion 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 then 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.
``<?php// assignment by reference\$x = 20;\$y = &\$x;echo \$x.'<br/>';echo \$y;?>``

Output

20
20

Because of assignment by value, the value of the 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
``<?php// assignment by reference\$x = 20;\$y = &\$x; \$x = 4;echo \$x.'<br/>';echo \$y;?>``

Output
4
4

See, the \$y is changed cause \$y is a reference to \$x.

In next article, we will learn about,
• php bitwise operators
• php logical operators
• php operators precedence Hi, I'm Sajjad Hossain, a PHP Developer working on PHP Development since 2012. If you have a project that you want to start you can contact me. I'm currently available for freelance work. Ping me on Facebook, WhatsApp or Skype.