PHP abs() Function

Definition and Usage

The abs() function is an in-built function in PHP iterpreter. This function accepts any number as argument and returns a positive value, disregarding its sign. Absolute value of any number is always positive.

This function always returns positive number.

Syntax

abs( mixed $num)

Parameters

Sr.No Parameter & Description
1 num
This parameter stores a value whose absolute value is to be obtained.

Return Values

PHP abs() function returns absolute value of num. If data type of num is float, return type is also float.For integer parameter, return type is integer.

PHP Version

This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.

Example

<?php
   $num="Hello";
   echo "String: " . $num . "
";    echo "absolute value : " . abs($num) . "
"; ?>

Output

This will produce the following result −

String: Hello
absolute value : 0
Updated on: 2026-03-11T23:22:53+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements