-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path021-defining-and-using-functions.php
More file actions
50 lines (44 loc) · 1.06 KB
/
021-defining-and-using-functions.php
File metadata and controls
50 lines (44 loc) · 1.06 KB
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
<?php
echo "<pre>";
myHello("Anthony");
function myHello($name = "Antonio") {
echo "Hello, $name\n";
}
myHello("Mariah");
myHello("Esther");
myHello("Vitória");
myHello();
function getHello(string $friend): string {
return "Hello, $friend\n";
}
echo getHello("Altair");
function result(float $num1, float $num2): float {
return $num1 + $num2;
}
echo "Sum: " . result(10.1, 20) . "\n";
function invisibleVariable() {
$name = "Thais";
}
invisibleVariable();
echo "My name is {$name} \n";
$nickName = "Thony";
function canNotAccess() {
$nickName = "Max";
echo "My nick name in \"canNotAccess\" is {$nickName}\n";
}
canNotAccess();
echo "My nick name after \"canNotAccess\" is {$nickName}\n";
function canAccess() {
global $nickName;
echo "My nick name in \"canAccess\" is {$nickName}\n";
$nickName = "Peter";
}
canAccess();
echo "My nick name after \"canAccess\" is {$nickName}\n";
function factorial(int $number): int {
if ($number == 0) {
return 1;
}
return $number * factorial($number - 1);
}
echo factorial(5) . "\n";