The abs()
function returns the absolute value of a number.
PHP abs() Function has the following syntax.
abs(number);
Parameter | Description |
---|---|
number | Required. A number. |
PHP abs()
function returns the absolute value of the number.
If the number is of type float, the return type is also float, otherwise it is integer.
You can either send a floating-point number or an integer to abs()
,
and it will return the same type:
<?PHP
echo abs(50); // 50
echo "\n";
echo abs(-12); // 12
echo "\n";
echo abs(50.1); // 50.1
echo "\n";
echo abs(-12.5); // 12.5
?>
The code above generates the following result.