Algorithm


Using Simple Arithematic expression

  1. Summation: $a + $b
  2. Subtraction: $a - $b
  3. Multiplication: $a * $b
  4. Division: $a / $b

 

Code Examples

#1 PHP Summation Example

Code - PHP Programming


<?php
  $a = 1;
  $b = 2;
  $sum = $a + $b;

  echo $sum; // 3
?>
Copy The Code & Try With Live Editor

Output

x
+
cmd
3

#2 PHP Subtraction Example

Code - PHP Programming


<?php
  $a = 10;
  $b = 20;
  $sub = $b - $a;

  echo $sub; // 10
?>
Copy The Code & Try With Live Editor

Output

x
+
cmd
10

#3 PHP Multiplication Example

Code - PHP Programming


<?php
  $a = 10;
  $b = 20;
  $mul = $a * $b;

  echo $mul; // 200
?>
Copy The Code & Try With Live Editor

Output

x
+
cmd
200

#4 PHP Division Example

Code - PHP Programming


<?php
  $a = 10;
  $b = 20;
  $div = $b / $a;

  echo $div; // 2
?>
Copy The Code & Try With Live Editor

Output

x
+
cmd
2
Advertisements

Demonstration


PHP Simple Summation, Subtraction, Multiplication, Division Example in PHP

Previous
PHP - Hello World Print
Next
PHP Reminder Example Solution