-
Notifications
You must be signed in to change notification settings - Fork 52
/
08_functions.php
38 lines (31 loc) · 706 Bytes
/
08_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
<?php
// 1. Function which prints "Hello I am TheCodeholic"
function hello()
{
echo 'Hello I am TheCodeholic<br>';
}
hello(); // 2
hello(); // 3
hello(); // 4
// 5. Create sum of two functions
function sum($a, $b)
{
echo ($a + $b) . '<br>'; // 5.3. return sum instead of printing
}
sum(4,5); // 5.1, 5.4. Add echo
sum(9,10); // 5.2, 5.6. Add echo
// 6. Create function to sum all numbers using ...$nums
//function sum(...$nums)
//{
// $sum = 0;
// foreach ($nums as $num) $sum += $num;
// return $sum;
//}
//echo sum(1, 2, 3, 4, 6);
//
//// 7 Arrow functions
//function sum(...$nums)
//{
// return array_reduce($nums, fn($coll, $n) => $coll + $n);
//}
//echo sum(1, 2, 3, 4, 6);