forked from assembler-institute/php-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
25 lines (21 loc) · 745 Bytes
/
functions.php
File metadata and controls
25 lines (21 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
// Create a function that given two numbers returns the sum of both
function sum($a,$b) {return $a + $b; };
// Create a function that given two numbers returns the multiplication of both
function mul($a, $b){ return $a * $b; };
// Create a function that given two numbers returns the division of both
function div($a, $b){ return $a / $b; };
// Create a function that, given two numbers and an operation (add, multiply or divide), returns the result of that operation.
function calc($a, $b, $operator){
switch ($operator) {
case "+":
echo sum($a, $b);
break;
case "*":
echo mul($a,$b);
break;
case "/":
echo div($a,$b);
break;
}
};