Learn PHP

PHP Arithmetic operator

The arithmetic operators handle basic numerical operations, such as addition and multiplication.

Operator Name Description
+ Addition Sum of $a and $b.
- Subtraction Difference of $a and $b.
* Multiplication Product of $a and $b
/ Division Quotient of $a and $b
% Modulus Remainder of $a divided by $b.
** Exponentiation Result of raising $a to the $b'th power. Introduced in PHP 5.6.
+= Shorthand addition Equivalent to $a = $a + $b.
-= Shorthand subtraction Equivalent to $a = $a - $b
*= Shorthand multiplication Equivalent to $a = $a * $b.
/= Shorthand division Equivalent to $a = $a / $b.

The division operator ("/") returns a float value unless the two operands are integers (or strings that get converted to integers) and the numbers are evenly divisible, in which case an integer value will be returned.

Operands of modulo are converted to integers (by stripping the decimal part) before processing

The result of the modulo operator % has the same sign as the dividend — that is, the result of $a % $b will have the same sign as $a


				      $a = 13; 
				      $b = 4; 
				      $c = 3.33; 
				      $d = 3.99999999; 
				      $e = -10; 
				      $f = -4; 

				      print $a + $b; 
				      print "\n"; 
				      print $a - $c; 
				      print "\n"; 
				      print $a * $d; 
				      print "\n"; 
				      print $a / $f; 
				      print "\n"; 
				      print $e % $b; 


		  			echo (5 % 3)."\n";           
					echo (5 % -3)."\n";          
					echo (-5 % 3)."\n";          
					echo (-5 % -3)."\n";         


		  			 if (($a % 2) == 1)
					  { echo "$a is odd." ;}
					  if (($a % 2) == 0)
					  { echo "$a is even." ;}


		  			for ($i = 1; $i <= 10; $i++) {
					    if(($i % 2) == 1)  //odd
					      {echo "<div class=\"dark\">$i</div>";}
					    else   //even
					      {echo "<div class=\"light\">$i</div>";}


		  			$d = dir('./');
				    $i = 0;
				    while(false !== ($e = $d->read())){
				            echo '<img src="'.$e.'"/>'.chr(10);
				                echo '<br/>';


		  			$x = 6;  
					$y = 4;

					echo $x + $y;


		  			$x = 15;  
					$y = 9;

					echo $x - $y;


		  			$x = 9;  
					$y = 5;

					echo $x * $y;


		  			$x = 12;  
					$y = 6;

					echo $x / $y;


		  			$x = 10;  
					$y = 5;

					echo $x % $y;

PHP Tutorials






Echo and Print Statement

Data Types



Number Convert

PHP String

php variable substitution in string

php string element

php string function

php addcslashes function

php addslashes function

php get magic quotes gpc function

php get meta tags function

php urlencode function

PHP $ and $$ Variables

PHP constant

PHP Magic Constants

PHP Static Variable

PHP Super Globals

PHP Globals

PHP Server

PHP reserved variable get

PHP reserved variable post

PHP reserved variable FILES

PHP reserved variable Cookies

PHP reserved variable Session

PHP reserved variable Request

PHP reserved variable environment

PHP Operator

PHP Arithmetic Operator

PHP Comparison Operator

PHP Incrementing and Decrementing Operators

PHP Identical Operators

PHP Logical Operators

PHP String Operators

PHP Ternary Operators

PHP Execution Operators

PHP Operator Precedence

PHP Array Operator

PHP Class

PHP Class Inheritance

PHP constructor and destructor

PHP abstract class

PHP class access control

PHP statement

PHP If statement

PHP else statement

PHP else if statement

PHP control structure statement

PHP while loop

PHP do while loop

PHP for loop

PHP for each loop

PHP break statement

PHP continue statement

PHP declare statement

PHP return statement

PHP require statement

PHP include

PHP require once

PHP include once

PHP goto statement

PHP function

PHP function parameter

PHP function scope

PHP array

PHP array operator

PHP array element loop

PHP array foreach loop

PHP array multidimensional

PHP html forms

PHP get and post method

form redirect

file inclusion

file i/o