-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforeach.php
83 lines (47 loc) · 1.19 KB
/
foreach.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
<?php
$things = array('Sgt. Pepper', "11", null, array(1,2,3), 3.14, "12 + 7", false, (string) 11);
fwrite(STDOUT, "let's check the values in our things!\n");
foreach ($things as $value) {
switch (gettype($value)) {
case "integer":
echo "$value is an integer\n";
break;
case "double":
echo "$value is a float\n";
break;
case "boolean":
echo var_export($value) . " is a boolean\n";
break;
case "array":
foreach ($value as $key => $arrayval) {
echo "$arrayval is indic $key in an array\n";
}
break;
case "NULL":
echo var_export($value) . " is null\n";
break;
case "string":
echo "$value is a string\n";
break;
}
}
fwrite(STDOUT, "\n\nNow let's look at all the scalars in our things\n");
foreach ($things as $key => $value) {
if (is_scalar($value)) {
echo var_export($value) . " is a scalar\n";
}
}
fwrite(STDOUT, "\n\nMatching the window in the excercise...\n");
foreach ($things as $key => $value) {
if (is_scalar($value)) {
echo "$value\n";
} else if (is_array($value)) {
echo "Array (";
foreach ($value as $indic) {
echo " $indic";
}
echo " )\n";
} else {
echo "\n";
}
}