Division¶
Division is the mathematical division. It applies to numbers: integers and float.
It also works with booleans and null, which are converted to integers. Other types are not allowed for division and yield a fatal error.
Division may be resulting in an integer or a float, whatever the type of the initial operands. PHP produces integers whenever possible.
Division by zero, or by any value that is cast to 0, leads to a DivisionByZeroError.
The operator for division is the slash /. The backslash \ is used for namespaces.
There is a function for the integer division: intdiv(); and % for the modulo operator, aka the remaining.
<?php
$a = 10 / 2.5; // 4.0
?>
See also Array operators and Combining arrays using + versus array_merge in PHP.
Related : Addition, Exponent, Multiplication, Modulo, DivisionByZeroError, intdiv()