-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconditionals.php
69 lines (56 loc) · 1.02 KB
/
conditionals.php
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
<?php
# CONDITIONAL
/*
==
===
<
>
<=
>=
!=
!==
*/
# IF-ELSE-IF
// $num = 6;
// if($num == 5) {
// echo '5 passed';
// }
// elseif($num == 6) {
// echo '6 passed'
// }
// else {
// echo 'did not pass';
// }
# NESTING IF
$num = 6;
// if($num > 4) {
// if($num < 10) {
// echo "$num passed";
// }
// }
/*
LOGICAL OPERATORS
and - && or AND (Both needs to be true) (&& is preferred over using AND)
or - || or OR (One of them or both, needs to be true) (|| is preferred over using OR)
xor - XOR (Exclusive OR - Only one needs to be true but not both)
not - ! (true if $x is not true)
*/
// if($num > 4 AND $num < 10) {
// echo "$num passed";
// }
# SWITCH
$favColor = 'blue';
switch($favColor) {
case 'red':
echo 'Your favourite color is red';
break;
case 'blue':
echo 'Your favourite color is blue';
break;
case 'green':
echo 'Your favourite color is green';
break;
default:
echo 'Your favourite color is something else';
}
?>