PHP: Arithmetic operators

This entry is part 19 of 54 in the series PHP Tutorial

Arithmetic operators work just like those we learnt in school.

ExampleNameResult
-$aNegationOpposite of $a
$a + $bAdditionSum of $a and $b.
$a - $bSubtractionDifference of $a and $b.
$a * $bMultiplicationProduct of $a and $b.
$a / $bDivisionQuotient of $a and $b.
$a % $bModulusRemainder of $a divided by $b.
<?php

echo (5 % 3);           
echo '<br>';
echo (5 + 3);         
echo '<br>';
echo (5 - 3);  
echo '<br>';
echo (12 / 4);  

?>

Series Navigation<< PHP: Creating multiline strings using heredoc <<<
PHP: Array >>

Leave a comment

Leave a Reply