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.
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)
?>Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
