abs()
abs() — Absolute value.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
Signature
abs(int|float $num): int|float
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $num | int|float | The numeric value to process |
Return value
The absolute value of num. If the argument num is of type float, the return type is also float, otherwise it is int (as float usually has a bigger value range than int).
Example
A runnable snippet:
var_dump(abs(-4.2)); var_dump(abs(5)); var_dump(abs(-5));
Output:
float(4.2) int(5) int(5)
Changelog
| Version | Change |
|---|---|
| 8.0.0 | num no longer accepts internal objects which support numeric conversion. |
All PHP 8.5 built-in functions
Reference card built from the PHP manual page abs() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.