Gen. partnerAlgotech

PHP function abs()

Absolute value of the number

|
September 11, 2019

Available in PHP 4.0, PHP 5, PHP 7

Absolute value of the number

Parameters

Parameter Data type Default value Note
$number mixed not Numeric conversion value
$cislo = -15.4;
$abs = abs($cislo); // 15.4

Returns the absolute value of the number.

Return values

number (int, float, ...)

  • Returns the absolute value of a number (i.e. unsigned).
  • If the input is a float, it will also return a float.
  • If the input is an integer, it returns an integer.
  • If the input is integer greater than the contents of integer, it will be mapped to float.
abs(5); // 5
abs(-3); // 3
abs(-3.14); // 3.14

Example

$abs = abs(-4.2); // $abs = 4.2; (double/float)
$abs2 = abs(5); // $abs2 = 5; (integer)
$abs3 = abs(-5); // $abs3 = 5; (integer)

The return values are listed in the comment

Other sources

[Official abs function documentation](PHP.net documentation)

Loading comments...

Stay in the loop

Subscribe to our newsletter and get the latest cybersecurity news delivered straight to your inbox.

Your data is safe. You can unsubscribe from the newsletter at any time.