Arithmetic Operators in PHP

Operator    Example            Action
+               $b = $a + 3;      Adds values
–                $b = $a – 3;       Subtracts values
*                $b = $a * 3;       Multiplies values
/                $b = $a / 3;        Divides values
%               $b = $a % 3;      Returns the modulus, or remainder

Example:
<HTML>
<HEAD>
<TITLE>Using Arithmetic Operators</TITLE>
</HEAD>
<BODY>
<?
$a = 85;
$b = 24;
echo “<P>Original value of $a is $a and $b is $b</P>”;
$c = $a + $b;
echo “<P>Added $a and $b and got $c</P>”;
$c = $a – $b;
echo “<P>Subtracted $b from $a and got $c</P>”;
$c = $a * $b;
echo “<P>Multiplied $a and $b and got $c</P>”;
$c = $a / $b;
echo “<P>Divided $a by $b and got $c</P>”;
$c = $a % $b;
echo “<P>The modulus of $a and $b is $c</P>”;
?>
</BODY>
</HTML>

About the author

Being the CEO and Founder of ClecoTech International, Mr. Ashish Prajapati is dedicated towards his aim of mentoring young startups into a full-fledged businesses. He is helping startups from America, Europe, India, and various other countries through proper guidance and the use of latest technologies to develop their innovation and ideas into definite realities.

Leave a Reply

Your email address will not be published.