forked from Kiotolabs/structured-programming-lab3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab3_task3.php
More file actions
84 lines (73 loc) · 2.13 KB
/
lab3_task3.php
File metadata and controls
84 lines (73 loc) · 2.13 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
79
80
81
82
83
84
<?php
/**
* ICS 2371 — Lab 3: Control Structures I
* Task 3: switch-case and match Expression [6 marks]
*
* @author [Kevin Mutua]
* @student [ENE212-0078/2023]
* @lab Lab 3 of 14
* @unit ICS 2371
* @date [1 April 2026]
*/
// ==========================================
// Exercise A — Day of Week Classifier
// ==========================================
$day = 3; // Change this to test 1-7
echo "<h3>Exercise A: Day Classifier</h3>";
switch ($day) {
case 1:
echo "Monday — Lecture day<br>";
break;
case 2:
echo "Tuesday — Lecture day<br>";
break;
case 3:
echo "Wednesday — Lecture day<br>";
break;
case 4:
echo "Thursday — Lecture day<br>";
break;
case 5:
echo "Friday — Lecture day<br>";
break;
case 6:
case 7:
echo "Weekend<br>";
break;
default:
echo "Invalid day<br>";
}
echo "<hr>";
// ==========================================
// Exercise B — HTTP Status Code Explainer
// ==========================================
$status_code = 404;
echo "<h3>Exercise B: HTTP Explainer (Switch)</h3>";
switch ($status_code) {
case 200: echo "200: OK"; break;
case 301: echo "301: Moved Permanently"; break;
case 400: echo "400: Bad Request"; break;
case 401: echo "401: Unauthorized"; break;
case 403: echo "403: Forbidden"; break;
case 404: echo "404: Not Found"; break;
case 500: echo "500: Internal Server Error"; break;
default: echo "Unknown Status Code"; break;
}
echo "<hr>";
// ==========================================
// Exercise C — PHP 8 match Rewrite
// ==========================================
echo "<h3>Exercise C: HTTP Explainer (Match)</h3>";
// match is an expression, so we can assign its result to a variable
$explanation = match ($status_code) {
200 => "200: OK",
301 => "301: Moved Permanently",
400 => "400: Bad Request",
401 => "401: Unauthorized",
403 => "403: Forbidden",
404 => "404: Not Found",
500 => "500: Internal Server Error",
default => "Unknown Status Code",
};
echo $explanation;
?>