PHP Arithmetic Operators

PHP Arithmetic Operators are used to perform basic arithmetic operations on numerical values in PHP. The arithmetic operators in PHP are similar to other programming languages and allow you to perform addition, subtraction, multiplication, division, modulus, and exponentiation operations.

These operators can be used with numeric data types such as integers, floating-point numbers, and doubles. They are useful when performing calculations or manipulating numeric values within a PHP program. Arithmetic operators can be used with variables, constants, and literal values.

PHP Arithmetic Operators are used to perform basic arithmetic operations on numerical values. Here are the arithmetic operators in PHP:

  1. Addition (+): Adds two values Example:
 
$a = 10;
$b = 20;
$c = $a + $b; // $c is 30
  1. Subtraction (-): Subtracts the second value from the first value Example:.
$a = 20;
$b = 10;
$c = $a - $b; // $c is 10
  1. Multiplication (*): Multiplies two values Example:
$a = 5;
$b = 6;
$c = $a * $b; // $c is 30
  1. Division (/): Divides the first value by the second value Example:
$a = 20;
$b = 5;
$c = $a / $b; // $c is 4
  1. Modulus (%): Returns the remainder of the first value divided by the second value Example:
$a = 20;
$b = 3;
$c = $a % $b; // $c is 2
  1. Exponentiation (**): Raises the first value to the power of the second value Example:
$a = 2;
$b = 3;
$c = $a ** $b; // $c is 8
Operator NameExample
addition operator (+)2+2 output 4
subtraction operator (-)4-1 output  3
division operator (/)10/2 output 5
modulus operator (%)3*2 output 6
multiplication operator (*)

3*2 output 6

Logical OperatorsAnd or &&,or or ||,Xor
String Operators

 .(Dot)

Example for PHP Arithmetic Operators

<?php
$n=40;
$m=20;
$total=$n+$m; //addition
echo "Addition of two Number:$total<br />";
$total=$n-$m; //subtraction
echo "Subtraction of two Number:$total <br />";
$total=$n*$m; // multiplication
echo "Multiplication of two Number:$total<br />";
$total=$n/$m; //division
echo "Division of two number:$total";
?>