PHP is_finite() function
The is_finite()
function in PHP is used to check whether a given value is a finite number. It returns true
if the value is finite and false
if it is infinite or not a number (NaN).
Syntax:
Parameters:
- $value: The number or expression you want to check.
Return Value:
- true if the number is finite (i.e., it is not infinite or NaN).
- false if the number is infinite or NaN.
Example 1: Checking Finite Values
Output:
Example 2: Checking Infinite Values
Output:
Example 3: Checking NaN (Not a Number)
Output:
Practical Usage:
You can use is_finite()
to validate numbers when performing calculations where it's important that the result is a finite number, for instance, in physics simulations, finance calculations, or when working with scientific data.
Summary:
is_finite()
checks whether a number is finite (not infinite or NaN).- It's commonly used to ensure calculations do not result in infinite values or errors caused by undefined mathematical operations.