PHP Operators Previous
Next PHP Assignment Operators
The arithmetic operators are used to perform mathematical calculation like addition, multiplication, division and modulus with numeric value in PHP
# |
Operator |
Operator Name |
Example |
1 |
+ |
Addition |
A + B |
2 |
- |
Substraction |
A - B |
3 |
* |
Multiplication |
A * B |
4 |
/ |
Division |
A / B |
5 |
% |
Modulus |
A % B |
Filename: php / arithmetic1.php
Code |
<?php
//arithmetic1
$a = 15;
$b = 31;
$c = $a + $b;
echo "$a + $b = $c";
?>
|
Running Step.
Type URL - https://localhost/php/arithmetic1.php
Filename: php / arithmetic2.php
Code |
<?php
//arithmetic2
$a = 862;
$b = 27;
$c = $a - $b;
echo "$a - $b = $c";
?>
|
Running Step.
Type URL - https://localhost/php/arithmetic2.php
Filename: php / arithmetic3.php
Code |
<?php
//arithmetic3
$a = 60;
$b = 58;
$c = $a * $b;
echo "$a * $b = $c";
?>
|
Running Step.
Type URL - https://localhost/php/arithmetic3.php
Filename: php / arithmetic4.php
Code |
<?php
//arithmetic4
$a = 907;
$b = 77;
$c = $a / $b;
echo "$a / $b = $c";
?>
|
Running Step.
Type URL - https://localhost/php/arithmetic4.php
Output |
907 / 77 = 11.779220779221
|
Filename: php / arithmetic5.php
Code |
<?php
//arithmetic5
$a = 98;
$b = 44;
$c = $a % $b;
echo "$a % $b = $c";
?>
|
Running Step.
Type URL - https://localhost/php/arithmetic5.php
Tags: PHP