PHP abs() Function
In this chapter you will learn:
- Definition for PHP abs() Function
- Syntax for PHP abs() Function
- Parameter for PHP abs() Function
- Return for PHP abs() Function
- Example - Get the absolute value
Definition
The abs()
function returns the absolute value of a number.
Syntax
PHP abs() Function has the following syntax.
abs(number);
Parameter
Parameter | Description |
---|---|
number | Required. A number. |
Return
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.
Example
You can either send a floating-point number or an integer to abs()
,
and it will return the same type:
<?PHP/* j a v a 2 s . c o m*/
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.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP acos() Function
- Syntax for PHP acos() Function
- Parameter for PHP acos() Function
- Return for PHP acos() Function
- Example - Calculate the arc cosine value
Home » PHP Tutorial » PHP Math Functions