PHP Math functions for addition, subtraction, multiplication & division

Basic arithmetic operators in PHP

PHP uses +, -, * and / for the four basic arithmetic operations. Keep numeric input validated before using it in calculations.

$a = 12;
$b = 5;

echo $a + $b; // 17
echo $a - $b; // 7
echo $a * $b; // 60
echo $a / $b; // 2.4

This is the recommended starting pattern. The detailed examples below are retained and modernized for additional variations and explanation.

Addition of two variables storing numbers.
$a=5;
$b=6;
$c=$a+$b;
echo $c;

Subtraction.

$a=8;
$b=10;
$c=$a-$b;
echo $c;

Multiplication

$a=3;
$b=14;
$c=$a*$b;
echo $c;// output 42

Division

$a=3;
$b=14;
$c=$a/$b;
echo $c; //Output  0.21428571428571
The output of division can be formatted to required decimal places

Questions

Modulus : remainder of a math division
Math Functions


Subscribe to our YouTube Channel here



plus2net.com







kakuyaw

06-03-2015

What is the value is not given, or not been initialize? Then what if i want to display my answer in textbox? Any idea?
smo

13-03-2015

Textbox value can be connected to display variable $c
echo "<input type=text name=t1 value=$c>";




PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer