PHP Math functions for addition, subtraction, multipication & division

Simple PHP functions to handle addition , subtraction , multiplications and divisions can be done by using built in functions.

Best way to learn is to develop some sample scripts.

Here are some of them.

Let us start with simple addition of two variables storing numbers.
$a=5;
$b=6;
$c=$a+$b;
echo $c;
Now try a 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
Visitors Rating
Your Rating





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>";

Post your comments , suggestion , error , requirements etc here .




HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer