English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

The abs() function in PHP

Theabs()The function returns the absolute value of the number.

Syntax

abs(num)

Parameter

  • num-We want to get the absolute value of the number. If num is a float, the return type is float, otherwise it is an integer.

returns

Theabs()The function returns the absolute value of the specified number.

Example

<?php
   echo(abs(3.1)  .  "<br>");
   echo(abs(-9.7)  .  "<br>");
?>

Output Result

3.1<br>9.7<br>

Let's see another example-

Example

<?php
   echo(abs(20)  .  "<br>");
   echo(abs(-50)  .  "<br>");
?>

Output Result

20<br>50<br>