-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6-Conditional Statement.php
More file actions
77 lines (77 loc) · 2.2 KB
/
6-Conditional Statement.php
File metadata and controls
77 lines (77 loc) · 2.2 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
//-----------------------------------
// -> If Statement
//-----------------------------------
$t = 14;
$a = "14";
if ($t === $a) {
echo "Have a good day!";
}
//-----------------------------------
$a = 200;
$b = 33;
$c = 500;
if ($a > $b && $a < $c ) {
echo "<br> Both conditions are true";
}
//-----------------------------------
$a = 5;
if ($a == 2 || $a == 3 || $a == 4 || $a == 5 || $a == 6 || $a == 7) {
echo "<br> $a is a number between 2 and 7";
}
//-----------------------------------
// -> if...else Statement
//-----------------------------------
$t = date("H"); // It returns the current hour in 24-hour format (from 00 to 23)
// echo "<br>". $t ;
print "<br>";
if ($t < "10") {
echo "Have a good morning!";
} else if ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
};
//-----------------------------------
// -> Short Hand If
//-----------------------------------
$a = 5;
print "<br>";
if ($a < 10) $b = "Hello";
echo $b;
//-----------------------------------
// -> Ternary Operators, or Conditional Expressions
//-----------------------------------
print "<br>";
$a = 13;
$b = $a < 10 ? "Hello" : "Good Bye";
echo $b;
//-----------------------------------
// -> switch Statement
$favcolor = "red";
print "<br>";
switch ($favcolor) {
case "red":
echo "Your favorite color is red!";
break;
case "blue":
echo "Your favorite color is blue!";
break;
case "green":
echo "Your favorite color is green!";
break;
default:
echo "Your favorite color is neither red, blue, nor green!";
}
//-----------------------------------
?>
</body>
</html>