w3resource

PHP: abs() function

abs() function

The abs() function is used to get the absolute (positive) value of a given number.

Version:

(PHP 4 and above)

Syntax:

abs(number)

Parameter:

Name Description Required /
Optional
Type
number Numeric value. Required Float/integer

Return value:

The absolute value of number.

Value Type: Float/integer depends on the type of number.

PHP: Absolute Value Function (abs)

PHP: abs function

Example:

$val1=-14.2;
$val2= 15;
$val3= -55;
$abs1=abs($val1);
$abs2=abs($val2);
$abs3=abs($val3);
echo "absolute value of $val1 is $abs1<br />";
echo "absolute value of $val2 is $abs2<br />";
echo "absolute value of $val3 is $abs3<br />";
?>

Sample Output:

absolute value of -14.2 is 14.2 
absolute value of 15 is 15 
absolute value of -55 is 55

View the example in the browser

Pictorial Presentation :

php math abs() function

See also

PHP Function Reference

Previous: Installing and configuring PHP for Math functions
Next: acos



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/php/function-reference/abs.php