-
Notifications
You must be signed in to change notification settings - Fork 0
/
function_scope.php
58 lines (53 loc) · 1.2 KB
/
function_scope.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
<?php
function fn(){
echo "inside the function,\$var=".$var."<br />";
$var = "contents 2";
echo "inside the function,\$var=".$var."<br />";
}
$var = "contents 1";
fn();
echo "outside the function,\$var=".$var."<br />";
?>
<?php
$var = "contents 1";
function fn1(){
echo "inside the function,\$var=".$var."<br />";
$var = "contents 2";
echo "inside the function,\$var=".$var."<br />";
}
fn1();
echo "outside the function,\$var=".$var."<br />";
?>
<?php
global $var;
function fn2(){
echo "inside the function,\$var=".$var."<br />";
$var = "contents 2";
echo "inside the function,\$var=".$var."<br />";
}
$var = "contents 1";
fn2();
echo "outside the function,\$var=".$var."<br />";
?>
<?php
function fn3(){
global $var;
echo "inside the function,\$var=".$var."<br />";
$var = "contents 2";
echo "inside the function,\$var=".$var."<br />";
}
$var = "contents 1";
fn3();
echo "outside the function,\$var=".$var."<br />";
?>
<?php
function fn4(){
echo "inside the function,\$var=".$var."<br />";
global $var;
$var = "contents 2";
echo "inside the function,\$var=".$var."<br />";
}
$var = "contents 1";
fn4();
echo "outside the function,\$var=".$var."<br />";
?>