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
46 lines (38 loc) · 908 Bytes
/
functions.php
File metadata and controls
46 lines (38 loc) · 908 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
//Create a function that given two numbers returns the sum of both
function sum($a, $b){
echo $a+$b;
}
sum(3,4);
echo "</br>";
//Create a function that given two numbers returns the multiplication of both
function multi($a, $b){
echo $a*$b;
}
multi(3,4);
echo "</br>";
//Create a function that given two numbers returns the division of both
function divi($a, $b){
echo $a/$b;
}
divi(3,4);
echo "</br>";
//Create a function that, given two numbers and an operation (add, multiply or divide), returns the result of that operation.
function calculate($number1, $number2, $operation){
if($operation == "+"){
echo $number1+$number2;
}
if($operation == "*"){
echo $number1*$number2;
}
if($operation == "/"){
echo $number1/$number2;
}
}
calculate(3,2,"+");
echo "</br>";
calculate(3,2,"*");
echo "</br>";
calculate(3,2,"/");
echo "</br>";
?>