# PHP Tutorails 5: PHP Operators and Kinds’

After the discussing about the “First PHP Project“, “How to Print” and “Variables in PHP“, we are now going to learn about **PHP Operators** in this tutorial.

## PHP Operators:

Actually operators perform operations on the data (values and variables) and return or give the outcome to us. For example in the below codes, (+) operator is performing the operation (adding two numbers).

1 2 3 4 |
<?php 2 + 4 = 6; ?> |

## Kinds of Operators:

Operators are divided into different groups in php. Below you can see the list of different groups of operators in PHP.

- Arithmetic operators
- Assignment operators
- Comparison operators
- Increment/Decrement operators
- Logical operators
- String operators
- Array operators

### Arithmetic PHP Operators:

The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.

Arithmetic operators are actually those mathematics operators which we learned in primary classes.

Operator | Name | Example | Result | |
---|---|---|---|---|

+ | Addition | $x + $y | Sum of $x and $y | |

– | Subtraction | $x – $y | Difference of $x and $y | |

* | Multiplication | $x * $y | Product of $x and $y | |

/ | Division | $x / $y | Quotient of $x and $y | |

% | Modulus | $x % $y | Remainder of $x divided by $y | |

** | Exponentiation | $x ** $y | Result of raising $x to the $y’th power (Introduced in PHP 5.6) |

Let’s work on example: create a new php file and save it in the directory we mentioned in second tutorial. Put the following codes inside and run the file through local server:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php $num1 = 4; $num2 = 3; //addition echo $num1 + $num2; //this will print 7 //subtraction echo $num1 - $num2; //this will print 1 //multiplication echo $num1 * $num2; //this will print 12 //division echo $num1 / $num2; //this will print 1 ?> |

### Assignment Operators:

The PHP assignment operators are used with numeric values to write a value to a variable. The basic assignment operator in PHP is “=”. Values on right side of the (=) are assigned to variables on the left. E.g.:

Operator | Operation | Discription |
---|---|---|

x = y | x = y | The left operand gets set to the value of the expression on the right |

x += y | x = x+y | Addition |

x -=y | x= x-y | Subtraction |

x *=y | x = x* y | Multiplication |

x /= y | x = x/y | Division |

x %=y | x = x%y | Modulus |

1 2 3 4 5 6 7 |
<?php $x = 50; $x += 100; // this is same as this code : $x = $x + 100 echo $x; // this will print 150 ?> |

Other **Operators **will be discussed on the next tutorial. Stay tuned with codejow.com