-
Notifications
You must be signed in to change notification settings - Fork 0
/
CH_5_4.php
79 lines (62 loc) · 1.55 KB
/
CH_5_4.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
<?php
/**
* 変数のスコープを理解する
* Created by IntelliJ IDEA.
* User: ishitsuka
* Date: 13/04/19
* Time: 15:08
* To change this template use File | Settings | File Templates.
*/
// 変数のスコープ
$dinner = 'Curry Cuttlefish';
function vegetarian_dinner() {
print "Dinner is $dinner, or ";
$dinner = "Sauteed Pea Shoots";
print $dinner;
print "\n";
}
function kosher_dinner() {
print "Dinner is $dinner, or ";
$dinner = 'Kung Pao Chicken';
print $dinner;
print "\n";
}
print "Vegetarian ";
vegetarian_dinner();
print "Kosher ";
kosher_dinner();
print "Regular dinner is $dinner";
// $GLOBALS配列
print "\n";
$dinner = 'Curry Cuttlefish';
function macrobiotic_dinner() {
$dinner = "Some Vegetables";
print "Dinner is $dinner";
// 海からの恵みに打ち負かされてしまう
print " but I'd rather have ";
print $GLOBALS['dinner'];
print "\n";
}
macrobiotic_dinner();
print "Regular dinner is: $dinner";
// GLOBALS配列の変数を修正する
$dinner = 'Curry Cuttlefish';
function hungry_dinner() {
$GLOBALS['dinner'] .= ' and Deep-Fried Taro';
}
print "Regular dinner is $dinner";
print "\n";
hungry_dinner();
print "Hungry dinner is $dinner";
// globalキーワード
$dinner = 'Curry Cuttlefish';
function vegetarian_dinner1() {
global $dinner;
print "Dinner was $dinner, but now it's ";
$dinner = 'Sauteed Pea Shoots';
print $dinner;
print "\n";
}
print "Regular Dinner is $dinner.\n";
vegetarian_dinner1();
print "Regular dinner is $dinner";