Appearance
Operators 
PODCAST
Arithmetic operators 
| operator | description | example | result | 
|---|---|---|---|
| + | addition | $x + $y | sum of $xand$y | 
| - | subtraction | $x - $y | difference of $xand$y | 
| * | multiplication | $x * $y | product of $xand$y | 
| / | division | $x / $y | quotient of $xand$y | 
| % | modulus | $x % $y | remainder of $xdivided by$y | 
| ** | power | $x ** $y | $xto the power$y | 
- Open course/arithmetic_operators.php
php
<article>
    <?php
    $x = 10;
    $y = 3;
    echo "<p> \$x = $x </p>\n";
    echo "<p> \$y = $y </p>\n";
    echo "<hr>\n";
    echo "<pre><code> \$x + \$y = $x + $y = " . ($x + $y) . "</code></pre>\n";
    echo "<pre><code> \$x - \$y = $x - $y = " . ($x - $y) . "</code></pre>\n";
    echo "<pre><code> \$x * \$y = $x * $y = " . ($x * $y) . "</code></pre>\n";
    echo "<pre><code> \$x / \$y = $x / $y = " . ($x / $y) . "</code></pre>\n";
    echo "<pre><code> \$x % \$y = $x % $y = " . ($x % $y) . "</code></pre>\n";
    echo "<pre><code> \$x ** \$y = $x ** $y = " . ($x ** $y) . "</code></pre>\n";
    ?>
</article>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15

REMARKS
- If you escape the dollar sign in a double-quoted (or heredoc) string, the corresponding variable won't be interpolated: echo "<p> \$x = $x </p>\n";results in$x = 10as output
- You can't (easily) include arithmetic operations in a double quoted string. Therefore, we resort to string concatenation in the statement echo "<pre><code> \$x + \$y = $x + $y = " . ($x + $y) . "</code></pre>\n";.
 You should also enclose the calculation($x + $y)with round brackets to get an error-free statement.- As an alternative, you could use an additional variable $sum = $x + $y, after which you can writeecho "<pre><code> \$x + \$y = $x + $y = $sum</code></pre>\n";
 
- As an alternative, you could use an additional variable 
Assignment operators 
| operator | description | example | result | 
|---|---|---|---|
| = | assign | $x = $y | |
| += | add and assign | $x += $y | $x = $x + $y | 
| -= | subtract and assign | $x -= $y | $x = $x - $y | 
| *= | multiply and assign | $x *= $y | $x = $x * $y | 
| /= | divide and assign quotient | $x /= $y | $x = $x / $y | 
| %= | divide and assign modulus | $x %= $y | $x = $x % $y | 
| .= | concatenate and assign | $x .= $y | $x = $x . $y | 
| ++ | increment and assign | $x++ | $x = $x + 1 | 
| -- | decrement and assign | $x-- | $x = $x - 1 | 
- Open course/assignment_operators.php
php
<article>
    <?php
    $x = 10;
    $y = 2;
    $z = 3;
    echo "<p> \$x = $x </p>\n";
    echo "<p> \$y = $y </p>\n";
    echo "<p> \$z = $z </p>\n";
    echo "<hr>\n";
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
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

Comparison operators 
| operator | description | example | result | 
|---|---|---|---|
| == | equal | $x == $y | trueif$xis equal to$y | 
| === | identical | $x === $y | trueif$xis equal to$yand they are of the same type | 
| !=<> | not equal | $x != $y$x <> $y | trueif$xis not equal to$y | 
| !== | not identical | $x !== $y | trueif$xis not equal to$yor they are not of the same type | 
| < | less than | $x < $y | trueif$xis less than$y | 
| <= | less than or equal to | $x <= $y | trueif$xis less than or equal to$y | 
| > | greater than | $x > $y | trueif$xis greater than$y | 
| >= | greater than or equal to | $x >= $y | trueif$xis greater than or equal to$y | 
- Open course/comparison_operators.php
php
<article>
    <?php
    $x1 = 10;
    $x2 = '10';
    $y = 5;
    echo "<p> \$x1 = $x1 </p>\n";
    echo "<p> \$x2 = '$x2' </p>\n";
    echo "<p> \$y = $y </p>\n";
    echo "<hr>\n";
    echo "<pre><code> (\$x1 == \$x2) = ($x1 == '$x2') = " . ($x1 == $x2) . "</code></pre>\n";
    echo "<pre><code> (\$x1 === \$x2) = ($x1 === '$x2') = " . ($x1 === $x2) . "</code></pre>\n";
    echo "<pre><code> (\$x1 != \$y) = ($x1 != $y) = " . ($x1 != $y) . "</code></pre>\n";
    echo "<pre><code> (\$x2 <> \$y) = ('$x2' <> $y) = " . ($x2 <> $y) . "</code></pre>\n";
    echo "<pre><code> (\$x1 < \$y) = ($x1  < $y) = " . ($x1 < $y) . "</code></pre>\n";
    echo "<pre><code> (\$x1 > \$y) = ($x1 > $y) = " . ($x1 > $y) . "</code></pre>\n";
    echo "<pre><code> (\$x2 > \$y) = ('$x2' > $y) = " . ($x2 > $y) . "</code></pre>\n";
    ?>
</article>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

REMARK
Notice that true is depicted as 1, while false corresponds to an empty string
Logical operators 
| operator | example | result | 
|---|---|---|
| and&& | $x and $y$x && $y | trueif both$xand$yare true | 
| or|| | $x or $y$x || $y | trueif either$xor$yis true | 
| xor | $x xor $y | trueif either$xor$yis true, but not both | 
| ! | !$x | trueif$xisfalse(nottrue) | 
- Open course/logical_operators.php
php
<article>
    <?php
    $x = 6;
    $y = 4;
    echo "<p> \$x = $x </p>\n";
    echo "<p> \$y = $y </p>\n";
    echo "<hr>\n";
    echo "<pre><code> (\$x < 8 and \$y > 3) = ($x < 8 and $y > 3) = " . ($x < 8 and $y > 3) . "</code></pre>\n";
    echo "<pre><code> (\$x < 8 && \$y > 6) = ($x < 8 && $y > 6) = " . ($x < 8 && $y > 6) . "</code></pre>\n";
    echo "<pre><code> (\$x < 8 or \$y > 3) = ($x < 8 or $y > 3) = " . ($x < 8 or $y > 3) . "</code></pre>\n";
    echo "<pre><code> (\$x < 8 || \$y > 6) = ($x < 8 || $y > 6) = " . ($x < 8 || $y > 6) . "</code></pre>\n";
    echo "<pre><code> (\$x < 8 xor \$y > 3) = ($x < 8 xor $y > 3) = " . ($x < 8 xor $y > 3) . "</code></pre>\n";
    echo "<pre><code> (\$x < 8 xor \$y > 6) = ($x < 8 xor $y > 6) = " . ($x < 8 xor $y > 6) . "</code></pre>\n";
    echo "<pre><code> !(\$x == \$y) = !($x == $y) = " . !($x == $y) . "</code></pre>\n";
    ?>
</article>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
