Simple Math in PHP

by Hiroshi on June 19, 2008

in General, Miscellaneous, PHP Basics

Do some Math in PHP. Here is how to do Summation, Multiplication, Subtraction, Division, Power and more in PHP.

Summation

<?php
$sum = 16 + 30;
echo $sum;
?>
<?php
$a = 26;
$b = 30;
$sum = $a + $b;
echo $sum;
?>

Multiplication

<?php
$a = 26;
$b = 30;
$c = 35;
$multiply = $a*$b*$c;
echo $multiply;
?>

Subtraction

<?php
$a = 26;
$b = 30;
$sub = $b-$a;
echo $sub;
?>

Division

<?php
$a = 26;
$b = 30;
$divide = $b/$a;
echo $divide;
?>

Power

<?php
$a = 26;
$b = 30;
$power = Pow($a, $b);
echo $power;
?>

Related Posts

Previous post:

Next post: