-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogical Operators in PHP.php
75 lines (65 loc) · 2.12 KB
/
Logical Operators in PHP.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
70
71
72
73
74
75
<!-- Logical Operators in PHP -->
<!-- Operators
1. && -> Logical AND -> (4<2)&&(4>3)- output False
2. || -> Logical OR -> (4<2)||(4>3)- output True
3. ! -> Logical Not -> !(4<2) -> output True
4. and -> Logical AND -> (4<2)and(4>3)- output False
5. or -> Logical OR -> (4<2)or(4>3)- output True
xor -> Exclusive OR ->(4<2)xor(4>3)- output True
&&/and
operand 1 -> true operand 2 -> true (output->True)
operand 1 -> true operand 2 -> false (output->false)
operand 1 -> false operand 2 -> true (output->false)
operand 1 -> false operand 2 -> false (output->false)
||/ or
operand 1 -> true operand 2 -> true (output->True)
operand 1 -> true operand 2 -> false (output->True)
operand 1 -> false operand 2 -> true (output->True)
operand 1 -> false operand 2 -> false (output->false)
!
operand-> false ->(output: True)
operand-> True ->(output: false)
xor
operand 1 -> true operand 2 -> true (output->false)
operand 1 -> true operand 2 -> false (output->True)
operand 1 -> false operand 2 -> true (output->True)
operand 1 -> false operand 2 -> false (output->false)
-->
<!-- Example -->
<?php
// &&
if((4<2)&&(4<2)){
echo "condition is true <br>";
}
else{
echo "condition is false <br>";
}
// and
if((10>5)and(4>1)){
echo "condition is true <br>";
}
else{
echo "condition is false <br>";
}
// ||
if((4<2)||(4>2)){
echo "condition is true <br>";
}
else{
echo "condition is false <br>";
}
// xor
if((20<2)xor(4<20)){
echo "condition is true <br>";
}
else{
echo "condition is false <br>";
}
// !
if(!(4>2)){
echo "condition is true <br>";
}
else{
echo "condition is false <br>";
}
?>