PHP abs

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

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 :

  1. $val1=-14.2;  

  2. $val2= 15;  

  3. $val3= -55;  

  4. $abs1=abs($val1);  

  5. $abs2=abs($val2);  

  6. $abs3=abs($val3);  

  7. echo "absolute value of $val1 is $abs1
    ";  

  8. echo "absolute value of $val2 is $abs2
    ";  

  9. echo "absolute value of $val3 is $abs3
    ";  

  10. ?>  

Output :

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

Pictorial Presentation :

php math abs() function

See also

PHP Function Reference