PHP.nl

Arithmetic Operators

Arithmetic Operators

Remember basic arithmetic from school? These work just like those.

| Example | Name | Result | | --- | --- | --- | | | Identity | Conversion of to or as appropriate. | | | Negation | Opposite of . | | | Addition | Sum of and . | | | Subtraction | Difference of and . | | | Multiplication | Product of and . | | | Division | Quotient of and . | | | Modulo | Remainder of divided by . | | | Exponentiation | Result of raising to the 'th power. |

The division operator returns a value unless the two operands are (or

which are type juggled to ) and the numerator is a multiple of the divisor, in which case an integer value will be returned. For integer division, see . /``float``intnumeric stringsint``intdiv

Operands of modulo are converted to before processing. For floating-point modulo, see . int``fmod

The result of the modulo operator has the same sign as the dividend — that is, the result of will have the same sign as . For example:

%``$a % $b``$aVoorbeeld: The Modulo Operator

<?php
var_dump(5 % 3);
var_dump(5 % -3);
var_dump(-5 % 3);
var_dump(-5 % -3);
?>
int(2)
int(2)
int(-2)
int(-2)

Math functions