-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0304.php
More file actions
31 lines (20 loc) · 739 Bytes
/
0304.php
File metadata and controls
31 lines (20 loc) · 739 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
<?php
declare (strict_types = 1);
// This is a regular anonymous fn
// anonymouse fn is when you define fn as variable
$sumNum = function (int $num1, int $num2): int {
return $num1 + $num2;
};
echo $sumNum(3, 7);
// now if you want to avoide use of `use` keyword & if you want to pass fn as argument then use arrow fn
$multiplyNum = fn(int $num1, int $num2) => $num1 * $num2;
echo $multiplyNum(3, 7);
echo $sumNum(2, $multiplyNum(3, 4));
echo '<br>';
$currentYr = date('Y');
$salaryInc = function (int $current, int $groth) use ($currentYr) {
return $current + $groth + $currentYr;
};
echo $salaryInc(1000, 500);
$bonusInc = fn(int $current, int $per) => (($current * $per) / 100 + $currentYr);
echo $bonusInc(2000, 5);