PHP is_infinite() function
The is_infinite()
function in PHP is used to determine whether a given value is an infinite number. It returns true
if the value is infinite and false
if the value is finite or NaN (Not a Number).
Syntax:
Parameters:
- $value: The number or expression you want to check.
Return Value:
- true if the number is infinite (either positive or negative infinity).
- false if the number is finite or NaN.
Example 1: Checking Infinite Values
Output:
Example 2: Checking Finite Values
Output:
Example 3: Checking NaN (Not a Number)
Output:
Practical Usage:
is_infinite()
can be useful when you're performing mathematical operations that could result in extremely large numbers or involve division by zero. It helps detect infinite values and avoid potential issues in calculations.
Summary:
is_infinite()
checks if a value is infinite (positive or negative).- It returns
true
for infinite values andfalse
for finite numbers or NaN.