34,333
edits
Changes
→PHP Arithmetic Operators
<td>%<td>Modulus<td>Returns the reminader from dividing the first operand by the second<td> $total = 20%10;
</table>
== PHP Increment and Decrement Operators ==
When programming in any language it is not uncommon to need to increment or decrement the value stored in a variable by 1. This could be done long hand:
<pre>
$myVar = $myVar -1;
</pre>
A much quicker way, however, is to use the PHP increment and decrement operators. These consist of the operators ''++'' (to increment) and ''--'' (to decrement) combined with an operand (the name of the variable to whcih the change is to be applied).
Their are two ways of using these operators, ''pre'' and ''post''. The ''pre'' mode performs the incrment or decrement ''before'' performign the rest of the expression. For example, you might want to increment the value of a variable before it is assigned to another variable, or used in a calculation. In the ''post'' mode the increment or decrement is performed after the expression a has been performed. In this instance you might want the value to be decrement after it has been assigned or used in a calculation.
Whether a pre or post is used depends on whether the operator appears before (for pre), or after (for post) the variable name in the expression.
The following table outlines the various forms of pre and post increment and decrement operatrors, together with examples that show how the equivalent task would need to be performed without the increment and decrement operators.
== PHP String Concatenation Operator ==