PHP abs() Function

Definition

The abs() function returns the absolute value of a number.

Syntax

PHP abs() Function has the following syntax.

abs(number);

Parameter

ParameterDescription
numberRequired. 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//from   w  w  w.j  ava 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.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions