php8.5
Home/ Manual/ math / functions/ abs

abs

PHP function Edit on GitHub ✎

(PHP 4, PHP 5, PHP 7, PHP 8)

Absolute value

Description

abs(int|float $num): int|float

Returns the absolute value of num.

Parameters

num

The numeric value to process

Return Values

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).

Changelog

VersionDescription
8.0.0num no longer accepts internal objects which support numeric conversion.

Examples

abs() example

php
<?php
var_dump(abs(-4.2));
var_dump(abs(5));
var_dump(abs(-5));
?>

The above example will output:

output
float(4.2)
int(5)
int(5)

See Also

Source: reference/math/functions/abs.xml · from the official PHP manual (php/doc-en)