How to Use PHP’s is_finite() to Validate Finite Float Values
This guide explains PHP’s is_finite() function, its purpose, accepted parameter, return behavior, and provides a clear code example showing how to determine whether a floating‑point number is a finite value on the current platform.
Purpose of is_finite()
The is_finite() function checks whether a given value is a legal, finite floating‑point number within the range allowed by the host platform’s PHP implementation.
Signature
bool is_finite(float $val)Parameters
$val – The value to be examined.
Return Value
Returns TRUE if $val is a finite float; otherwise returns FALSE (e.g., for INF, -INF, or NaN).
Example Usage
<?php
echo is_finite(2); // 1 (TRUE)
echo is_finite(log(0)); // 0 (FALSE) – log(0) yields -INF
echo is_finite(2000); // 1 (TRUE)
?>Expected Output
1
1The first and third calls return 1 because the arguments are finite numbers, while the second call returns 0 because log(0) produces an infinite value.
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.
