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
45 lines (28 loc) · 790 Bytes
/
functions.php
File metadata and controls
45 lines (28 loc) · 790 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
<?php
#Create a function that given two numbers returns the sum of both
function sum(int $x, int $y)
{
return $x + $y;
}
echo sum(10, 25);
echo "<br>";
#Create a function that given two numbers returns the multiplication of both
function multiply(int $a, int $b) {
return $a * $b;
}
echo multiply(10, 10);
echo "<br>";
#reate a function that given two numbers returns the division of both
function division(int $c, int $d) {
return $c / $d;
}
echo division(20, 5);
echo "<br>";
#Create a function that, given two numbers and an operation (add, multiply or divide), returns the result of that operation.
function operation ($f, $g, $operation){
if($operation == "multiply"){
return $f * $g;
}
}
echo operation(3, 5, "multiply");
?>