abs() function in PHP


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

Syntax

abs(num)

Parameters

  • num − The number for which we want to get the absolute value. If the num is float, then the return type will be float, otherwise it is an integer.

Return

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

Example

 Live Demo

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

Output

3.1<br>9.7<br>

Let us see another example −

Example

 Live Demo

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

Output

20<br>50<br>

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Jun-2020

148 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements