PHP | abs( ) Function
The abs() fuction is a built-in function in PHP and is used to return the absolute (positive) value of a number. The abs() function in PHP is identical to what we call modulus in mathematics. The modulus or absolute value of a negative number is positive.
Syntax:
abs(value)
Parameter: The abs() function accepts a single parameter value which is the number whose absolute value you want to find.
Return Value: It returns the absolute value of the number passed to it as argument.
Examples:
Input : abs(6) Output : 6 Input : abs(-6) Output : 6 Input : abs(6.4) Output : 6.4 Input : abs(-6.4) Output : 6.4
Below programs illustrate the abs() function in PHP:
-
When a positive number is passed as a parameter:
<?phpecho (abs(6);?>chevron_rightfilter_noneOutput:
6
-
When a negative number is passed as a parameter:
<?phpecho (abs(-6);?>chevron_rightfilter_noneOutput:
6
-
When a positive number with decimal places is passed as a parameter:
<?phpecho (abs(6.4);?>chevron_rightfilter_noneOutput:
6.4
-
When a negative number with decimal places is passed as a parameter:
<?phpecho (abs(-6.4);?>chevron_rightfilter_noneOutput:
6.4
Reference:
http://php.net/manual/en/function.abs.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- PHP | ord() Function
- D3.js | d3.set.add() Function
- CSS | rgb() Function
- D3.js | d3.lab() Function
- p5.js | box() Function
- PHP | each() Function
- CSS | hsl() Function
- D3.js | d3.map.set() Function
- D3.js | d3.hcl() Function
- p5.js | nfc() function
- p5.js | nf() Function
- PHP | Ds\Map put() Function
- PHP | exp() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



