PHP abs () function
Examples
Returns the absolute value of different numbers:
<?php
echo(abs(6.7) . "<br>");
echo(abs(-6.7) . "<br>");
echo(abs(-3) . "<br>");
echo(abs(3));
?>
echo(abs(6.7) . "<br>");
echo(abs(-6.7) . "<br>");
echo(abs(-3) . "<br>");
echo(abs(3));
?>
Running instance »
Definition and Usage
abs () function returns the absolute value of a number.
grammar
abs( number );
参数 | 描述 |
---|---|
number | 必需。规定一个数。如果数字的类型是浮点型,则返回的类型也是浮点型,否则将以整数形式返回。 |
technical details
return value: | number of absolute value. |
---|---|
Return type: | Float / Integer |
PHP version: | 4+ |
PHP Math Reference