PHP abs() Function

Definition and Usage

The abs() function returns the absolute value of a number.

Syntax

abs(x)
Parameter Description
x Required. A number.

Description

returns the parameter x absolute value. If the parameter x If the type is float, the returned type is also float, otherwise it returns integer (because float usually has a larger value range than integer).

Example

<?php
echo(abs(6.7));
echo(abs(-3));
echo(abs(3));
?>

Output:

6.7
3
3