-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperators.php
105 lines (99 loc) · 1.98 KB
/
operators.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
$a = 10;
$b = 5;
$c = "10";
// Arithmetic operators
$addition = $a + $b; // 15
$subtraction = $a - $b; // 5
$multiplication = $a * $b; // 50
$division = $a / $b; // 2
$modulus = $a % $b; // 0
// Comparison operators
$equal = $a == $b; // false
$notEqual = $a != $b; // true
$equalStrict = $a === $c; // false
$notEqualStrict = $a !== $c; // true
$greaterThan = $a > $b; // false
$lessThan = $a < $b; // true
$greaterThanOrEqual = $a >= $b; // false
$lessThanOrEqual = $a <= $b; // true
// Logical operators
$and = $a && $b; // false
$or = $a || $b; // true
$not = !$a; // false
// Assignment operators
$a += $b; // 15
$a -= $b; // 5
$a *= $b; // 50
$a /= $b; // 2
$a %= $b; // 0
var_dump([
'arithmetic' => [
'addition' => $addition,
'subtraction' => $subtraction,
'multiplication' => $multiplication,
'division' => $division,
'modulus' => $modulus
],
'comparison' => [
'equal' => $equal,
'notEqual' => $notEqual,
'equalStrict' => $equalStrict,
'notEqualStrict' => $notEqualStrict,
'greaterThan' => $greaterThan,
'lessThan' => $lessThan,
'greaterThanOrEqual' => $greaterThanOrEqual,
'lessThanOrEqual' => $lessThanOrEqual
],
'logical' => [
'and' => $and,
'or' => $or,
'not' => $not
]
]);
/*
Output:
array(3) {
["arithmetic"]=>
array(5) {
["addition"]=>
int(15)
["subtraction"]=>
int(5)
["multiplication"]=>
int(50)
["division"]=>
int(2)
["modulus"]=>
int(0)
}
["comparison"]=>
array(8) {
["equal"]=>
bool(false)
["notEqual"]=>
bool(true)
["equalStrict"]=>
bool(false)
["notEqualStrict"]=>
bool(true)
["greaterThan"]=>
bool(true)
["lessThan"]=>
bool(false)
["greaterThanOrEqual"]=>
bool(true)
["lessThanOrEqual"]=>
bool(false)
}
["logical"]=>
array(3) {
["and"]=>
bool(true)
["or"]=>
bool(true)
["not"]=>
bool(false)
}
}
*/