(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

is_finiteFinds whether a value is a legal finite number


is_finite(float $num): bool

Checks whether num is a legal finite on this platform.



The value to check

Return Values

true if num is a legal finite number within the allowed range for a PHP float on this platform, else false.

See Also

add a note

User Contributed Notes 1 note

Daniel Klein
6 years ago
(is_finite($float)) is equivalent to (!is_infinite($float) && !is_nan($float)), i.e. a number can only be one of finite, infinite and NaN. You don't need to check both is_infinite() and is_nan() to see if a number is invalid or out of range.

= 42;
$infinite = log(0);
$nan = acos(2);

var_dump(is_finite($finite), is_infinite($finite), is_nan($finite)); // true, false, false
var_dump(is_finite($infinite), is_infinite($infinite), is_nan($infinite)); // false, true, false
var_dump(is_finite($nan), is_infinite($nan), is_nan($nan)); // false, false, true
To Top