### Arithmetic and Assignment Operators

An operator is the most important term in php language like other programming languages. Because without these operators it is impossible to implement logic, compare, math and so on. In php language, there are almost 6+ types of operators. Most of them are highly used in developing work. Let's go through below.

1. Arithmetic Operator
2. Assignment Operators
3.  Comparison Operators
4. Increment / Decrement Operator
5. Logical Operators
6. String Operators
7. Array Operators

### Arithmetic Operators(+, - , *, /)

Arithmetic operators are mainly used for doing the calculation in PHP language. These operators are used for doing several calculations.  They are addition(+), subtraction(-), multiplication(*), division(/), modulas(%).  For adding two several numbers (+) is used. Let's an example from below;

``````
<!--?php

\$firstNum = 60;
\$secondNum = 50;
\$result = \$firstNum+\$secondNum;
echo \$result;

?-->``````

``````
110``````

In the same way, we can easily implement subtraction, multiplication and division also by using -, *,/.  Let's see the below PHP code where subtraction, multiplication and division are used.

``````
<!--?php

\$firstNum = 60;
\$secondNum = 50;
\$subResult = \$firstNum - \$secondNum; //subtraction
\$multiResult = \$firstNum * \$secondNum; //multiplication
\$divResult = \$firstNum / \$secondNum; //division
echo "The subtraction is " . \$subResult . "

Output of Subtraction, Multiplication and Division(combined):

The subtraction is 10
The multiplication is 3000
The division is 1.2

Use of Modulus (%)

Modulus is mainly used to find out the keeping value of a variable divided by another variable. This is applicable for integer value but also can be used for float/double values. For doing the modulus calculation modulus(%) operator is used.  For better understanding let's look below example

<!--?php

\$firstNum = 6;
\$secondNum = 5;
\$modulus = \$firstNum % \$secondNum;
echo \$modulus;

?-->

Output of modulus is

1

Assign Operators(=)

Assign operator is mainly an equal sign but it plays different duties in programming. In programming language, there is a confusion with equal(=) sign. Because it sometimes plays a role as an assignment operator or comparison operator. But there is a little bit of difference between them. Equal(=) is an assignment operator whereas double equal (==) is a comparison operator. We will discuss comparison(==) operator in upcoming next post. When the value of a variable is replaced by another value then it is called assign. For assigning a new value to a previously declared variable assign(=) operator is used. This is totally same as equal sign. Let's see an example for better clearance what is an assignment operator

<!--?php

\$num1 = 5; // value of num1 is 5
echo "Number1 value is " . \$num1 . "

Output :

Number1 value is 5
Number2 value is 10
Number1 value is 10

-->

``````
``` ```
``` (adsbygoogle = window.adsbygoogle || []).push({}); ```
``` ```
``` hljs.initHighlightingOnLoad(); (function() { // DON'T EDIT BELOW THIS LINE var d = document, s = d.createElement('script'); s.src = 'https://phpdark-1.disqus.com/embed.js'; s.setAttribute('data-timestamp', +new Date()); (d.head || d.body).appendChild(s); })(); hljs.initHighlightingOnLoad(); If you think you have query... then For contacting with us use  Facebook . You can also use  Github Important Contact Us Privacy Policy Terms & Conditions Faq Framework Codeigniter Laravel Contact Facebook Twitter Github Sitemap © Copyright PHPDark.com All Rights Reserved 2018-2021 | v1.7.0 window.fbAsyncInit = function() { FB.init({ xfbml : true, version : 'v5.0' }); }; (function(d, s, id) { var js, fjs = d.getElementsByTagName(s); if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = 'https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js'; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); ```