Home >>PHP Math Functions >PHP abs() Function

PHP abs() Function

PHP abs() Function

PHP abs() function is used to return the absolute (positive) value of a given input number. This abs() function is like the modulus in mathematics. The modulus or absolute value of any negative number will be positive.

Syntax:

   abs($number);

Parameter Values

Parameter Description
number This is a required parameter. This parameter defines the input number. If the given number is of float type then the return type will also be float, otherwise it will be integer type.

Here is an example of abs() function in PHP:

<html>
<body>

<?php

echo abs(-55) ."<br>";   // absolute of negative will also be positive
echo abs(55) ."<br>";

?>

</body>
</html>
Output:
55
55

Here is an another example of abs() function in PHP:

<html>
<body>

<?php

echo abs(-8.62) ."<br>";  // float type
echo abs(33.33);

?>

</body>
</html>
Output:
8.62
33.33

No Sidebar ads