PHP abs() Function – Returning the Absolute Value

This article explains PHP's abs() function, describing its numeric parameter, the type‑preserving return of the absolute value, and provides clear example code demonstrating usage with both integer and float inputs.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP abs() Function – Returning the Absolute Value

The abs() function in PHP returns the absolute value of a numeric argument.

Parameter: $number – the number (integer or float) to be processed.

Return value: The absolute value of $number. If the input is a float, the result is a float; otherwise, it is an integer.

Example:

<?php
$abs = abs(-4.2); // $abs = 4.2 (float)
$abs2 = abs(5);   // $abs2 = 5 (integer)
$abs3 = abs(-5);  // $abs3 = 5 (integer)
?>
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendPHPfunctionexampleABSabsolute-value
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.