-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06_functions.php
46 lines (32 loc) · 859 Bytes
/
06_functions.php
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
/* ------------ Functions ----------- */
/*
Functions are reusable blocks of code that we can call to perform a specific task.
We can pass values into functions to change their behavior. Functions have their own local scope as opposed to global scope
/*
** Function Syntax
function functionName($arg1, $arg2, ...) {
// code to be executed
}
*/
// $y = 12;
// function registerUser() {
// global $y;
// echo $y;
// echo "User Registered Successfully!";
// }
// registerUser();
function registerUser($email) {
echo $email . ' Registered Successfully!';
}
// registerUser('email');
function sum($num1 = 4, $num2 = 5) {
return $num1 + $num2;
}
// echo sum();
$subtract = function ($num1, $num2) {
return $num1 - $num2;
};
// echo $subtract(10, 5);
$multiply = fn ($num1, $num2) => $num1 * $num2;
echo $multiply(10, 5);