forked from assembler-institute/php-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconditionals.php
More file actions
75 lines (57 loc) · 1.98 KB
/
conditionals.php
File metadata and controls
75 lines (57 loc) · 1.98 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
<?php
#Create a simple condition that evaluates whether the current day is Monday. Only in the case that the condition is met, it shows a message of “We are on Monday”.
$t = date("Mon");
if (date("D") == $t) {
echo "We are on Monday";
}
else {
echo "Today is not Monday";
}
echo "<br><br>";
#Create a simple condition that evaluates whether the current month is October. If the condition is met, it shows a message of the type "We are in October". Otherwise, if this condition is not met, show the current month in words as it come from DateTime.
$m = date("October");
if (date("F") == $m) {
echo "We are in October";
}
else {
echo "Today is ", date("F");
}
echo "<br><br>";
#Create a double condition that evaluates:
#If the current minute is less than 10. Displays a message of type "the current minute is less than 10", if the current minute is greater than 15, displays a message of the type "the current minute is more than 15". If you do not meet any of the two conditions above: Displays a message of the type "does not meet any conditions”
if (date("i") < 10) {
echo "the current minute is less than 10";
}
else if (date("i") > 15) {
echo "the current minute is more than 15";
}
else {
echo "does not meet any conditions";
}
echo "<br><br>";
#Create a switch type control structure to display a different message depending on the current day of the week. You can write any type of message, because the important thing is that you understand how it works and in what cases you can use it.
$d = date("D");
switch ($d) {
case "Mon":
echo "Today is Monday";
break;
case "Tue":
echo "Today is Tuesday";
break;
case "Wed":
echo " Today is Wednesday";
break;
case "Thu":
echo " Today is Thursday";
break;
case "Fri":
echo " Today is Friday";
break;
case "Sat":
echo " Today is Saturday";
break;
case "Sun":
echo " Today is Sunday";
break;
}
?>