-
Notifications
You must be signed in to change notification settings - Fork 4
/
function.php
90 lines (73 loc) · 1.42 KB
/
function.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
// function
function my_function() {
echo "Hello World!";
}
my_function();
// call back function
$second = function() {
echo "Hello World!";
};
$second();
$sum = function($a, $b) {
return $a + $b;
};
echo $sum(1, 2);
echo "===================\n";
function my($number1, $number2, $fn) {
$result = $fn($number1, $number2);
$result = $result * 10;
echo $result . "\n";
}
my(1, 2, function($a, $b) {
return $a + $b;
});
my(1, 2, function($a, $b) {
return $a * $b;
});
my(1, 2, function($a, $b) {
return $a - $b;
});
my(1, 2, function($a, $b) {
});
// Run it!
// function() {
// print "Hey!\n";
// }();
(function() {
print "Hey!\n";
})();
(function($name) {
print "Hey $name!\n";
})("Reza");
$sayHey = function($name) {
print "Hey $name!\n";
};
$sayHey("Rey");
unset($sayHey);
function sum(...$numbers) {
$sum = 0;
foreach ($numbers as $number) {
$sum += $number;
}
return $sum;
}
print sum(1, 2, 3, 4)."\n";
function sum2($numbers) {
$sum = 0;
foreach ($numbers as $number) {
$sum += $number;
}
return $sum;
}
print sum2([1, 2, 3, 4])."\n";
// print sum([1, 2, 3, 4])."\n";
function func($a, $b, $c, int ...$numbers) {
$sum = 0;
foreach ($numbers as $number) {
$sum += ($number + $a - $b) * $c;
}
return $sum;
}
var_dump(func(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
// var_dump(func(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "hi"));