-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02LoopingStructures.php
More file actions
47 lines (40 loc) · 1.01 KB
/
Copy path02LoopingStructures.php
File metadata and controls
47 lines (40 loc) · 1.01 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
<html>
<head>
<title>WAP to implement Looping Structures</title>
</head>
<body>
<?php
// for loop
echo "Looping with for loop:<br>";
for ($i = 1; $i <= 5; $i++) {
echo "Iteration $i<br>";
}
// while loop
echo "Looping with while loop:<br>";
$j = 1;
while ($j <= 5) {
echo "Iteration $j<br>";
$j++;
}
// do-while loop
echo "Looping with do-while loop:<br>";
$k = 1;
do {
echo "Iteration $k<br>";
$k++;
} while ($k <= 5);
// foreach loop (Looping through an array )
echo "Looping through an array:<br>";
$fruits = array("Apple", "Banana", "Orange", "Grapes");
foreach ($fruits as $fruit) {
echo "$fruit<br>";
}
// foreach loop (Looping through an associative array)
echo "Looping through an associative array:<br>";
$person = array("name" => "Anas", "age" => 18, "city" => "Mumbai");
foreach ($person as $key => $value) {
echo "$key: $value<br>";
}
?>
</body>
</html>