PHP Operators: Assignment Operators Table
PHP Operators Step By Step Tutorial - Part 4: Assignment operator Table:
| Operator | Info | Example |
| = | Placing right side to left side | $r = 87 |
| += | Enhancing right side to left side | $r += 42 |
| -= | Tapering down right side to left side | $r -= 10 |
| *= | Multiply right side to left side | $r *= 2 |
| /= | Allot right side to left side | $r /= 7 |
| %= | Putting down the result of modulus between left side variable value with right side value in left | $r %= 1 or $r : = $r % 2 |
| &= | Putting down the result of operation the "AND" operator to the left side variable value with right side value in left. | $x &= $y or $x :=$x & $y |
| |= | Putting down the result of operation the "OR" operator to the left side variable value with right side value in left | $x |= $y or $x : = $x | $y |
| ^= | Putting down the result of operation the "XOR" operator to the left side variable value with right side value in left | $x ^= $y or $x : = $x ^ $y |
| .= | Putting down the result of operation the "CONCAT" operator to the left side variable value with right side value in left | >$x .= "more text" or $x : = $x."more text" |
Pay attention to the example of using assignment operator at script as following:
File name: assignmentoperator1.php
<html>
<head>
<title>Using Assignment Operator</title>
</head>
<body>
<h1>Operator Assignment</h1>
<?
$x = 15;
echo ("\$x = $x <br>");
$x += 1 ;
echo ("\$x += 1 = $x <br><br>");
$x = 7;
echo ("\$x = $x <br>");
$x = $x + 2;
echo ("\$x = \$x + 2 = $x <br><br>");
$x = 87;
echo ("\$x = $x <br>");
$y = &$x;
echo ("\$y = &\$x = $x <br><br>");
$greeting = "good";
echo ("\$greeting = $greeting <br><br>");
$greeting .="night";
echo ("\$greeting .= good = $greeting");
?>
</body>
</html>
The result of executing assignment operator.php:
