A trivial
$num = $num Try it Yourself »
Definition and Usage
The abs[] function returns the absolute [positive] value of a number.
Syntax
Parameter Values
ParameterDescription number
Required. Specifies a number. If the number is of type float, the return type is also float, otherwise it is integer
Technical Details
Return Value:The absolute value of the number
Return Type:Float / Integer
PHP Version:4+
❮ PHP Math Reference
View Discussion
Improve Article
Save Article
Read Discuss View Discussion
Improve Article
Save Article
The abs[] function is an inbuilt function in PHP which 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:
number abs[ value ]
Parameters: The abs[] function accepts single parameter value which holds 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:
Program 1: When a positive number is passed as a parameter:
Output:
6
Program 2: When a negative number is passed as a parameter:
Output:
6
Program 3: When a positive number with decimal places is passed as a parameter:
Output:
6.4
Program 4: When a negative number with decimal places is passed as a
parameter: