Arithmetic operators in PHP – PHP Lessons

What is the arithmetic operators in PHP?

<?php
$a + $b // sum of $a and $b
$a - $b // Difference $a and $b
$a * $b // Multiplication $a and $b
$a / $b // Division $a and $b
?>

There is another arithmetic operator PHP, so-called integer remainder of a division.

<?php
$a % $b
?>

If we divide 5 for example by 2, we get 2.5 and 5% 2, we get 1 (which is the residue left):

<?php
echo 5 / 2 // we get 2.5
echo 5 % 2 // we get 1
?>

Leave a Reply

Your email address will not be published. Required fields are marked *