-
Notifications
You must be signed in to change notification settings - Fork 0
/
variable.php
106 lines (78 loc) 路 1.94 KB
/
variable.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
91
92
93
94
95
96
97
98
99
100
101
<?php
/*
1. Local Variable
Defination: A variable declared in a function is considered local.
*/
echo "1. Local Variable:\n";
$x = 65;
function localVariable()
{
$x = 10;
echo "Local Scope Value: $x\n";
echo "=============================\n";
}
echo "Global Scope Value: $x\n";
localVariable();
/*
2. Functional Parameters
Defination: A function is a small unit of program which can take some input in the
form of parameters and does some processing and may return a value.
*/
echo "2. Functional Parameters:\n";
function addMultiply($value)
{
$value = $value * 10;
return $value;
}
$result = addMultiply(10);
echo "Functional Parameter Value: $result\n";
echo "=================================\n";
/*
3. Global Variable
Defination: A global variable can be accessed in any part of the program.
By placing the keyword GLOBAL in front of the variable that should be recognized as global.
*/
echo "3. Global Variable:\n";
$y = 25;
function showGlobal()
{
global $y;
$y++;
echo "Global Variable Value: $y\n";
}
showGlobal();
echo "=================================\n";
/*
4. Static Variable
Defination: The values which are destroyed on the function's exit,
a static variable will not lose its value when the function exits
and will still hold that value should the function be called again.
*/
echo "4. Static Variable:\n";
function showStatic()
{
static $count = 0;
$count++;
echo "Static Variable Value: $count\n";
}
showStatic();
showStatic();
echo "======= Constants==========\n";
define("MINSIZE", 50);
echo MINSIZE;
echo "\n";
echo "======= All Variables==========\n";
$intNum = 472;
$doubleNum = 29.3;
$boolean = true;
$string = 'Web Code Geeks';
$array = array("Pineapple", "Grapefruit", "Banana");
echo "integer: $intNum\n";
echo "float: $doubleNum\n";
echo "boolean: $boolean\n";
echo "string: $string\n";
echo "======= Array==========\n";
foreach ($array as $value) {
echo $value . "\n";
}
?>