-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloop.php
More file actions
78 lines (62 loc) · 1.34 KB
/
loop.php
File metadata and controls
78 lines (62 loc) · 1.34 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
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
<?php
//WHILE LOOP
echo "<hr>";
echo "<b>While Loop</b>";
echo "<br>";
$counter = 1;
while(($counter <=5)){
echo "The counter is: " . $counter;
echo "<br>";
$counter++;
}
//FOR LOOP
echo "<hr>";
echo "<b>For Loop</b>";
echo "<br>";
for($i = 1; $i <= 5; $i++){
echo "The counter is: " . $i;
echo "<br>";
}
//FOREACH LOOP
echo "<hr>";
echo "<b>Foreach Loop (Colors)</b>";
echo "<br>";
$colors = ["Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"]; //array
foreach($colors as $color){
echo "The color is: " . $color;
echo "<br>";
}
//FOREACH LOOP - students
echo "<hr>";
echo "<b>Foreach Loop (Students)</b>";
echo "<br>";
$student1 = [
//KETY => VALUE pair
"id" => 1001,
"firstname" => "Juan",
"lastname" => "Dela Cruz"
];
$student2 = [
//KETY => VALUE pair
"id" => 1002,
"firstname" => "Brent",
"lastname" => "Da Mage"
];
$students = [$student1, $student2];
//DEBUGGING PURPOSES
// echo "<pre>";
// var_dump($students); exit;
// echo "<pre>";
//FOREACH FOR ONE STUDENT
// foreach($student1 as $key => $value){
// echo "The student's " . $key . " is " . $value;
// echo "<br>";
// }
foreach($students as $student){
//key-value pair
foreach($student1 as $key => $value){
echo "The student's " . $key . " is " . $value;
echo "<br>";
}
}
?>