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
47 lines (40 loc) · 1.77 KB
/
conditionals.php
File metadata and controls
47 lines (40 loc) · 1.77 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
<?php
$d = new DateTime();
$wd = $d->format('D');
$M = $d->format("F");
$m = $d->format("i");
$iso = $d->format("N");
// 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”.
if ($wd == "Mon") echo "We are on Monday";
else echo "IT'S WEDNSDAY MY DUDES UEEEEEEEEEEEEH";
echo "<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.
if($M == "October") echo "We are in October";
else echo $M;
echo "<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 ($m <10) echo "the current minute is less than 10";
else if( $m<15) echo "the current minute is more than 15";
else echo "does not meet any conditions";
echo "<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.
$switch = match(true){
$iso == 1 => "Lunes",
$iso == 2 => "Martes",
$iso == 3 => "Miércoles",
$iso == 4 => "Jueves",
$iso == 5 => "Viernes",
$iso == 6 => "Sábado",
$iso == 7 => "Domingo",
default => "Nah"
};
echo $switch;