is_finite()
` and `is_infinite()
` functions to check if a numeric value is finite or infinite.is_finite()
` function returns `true
` if the given value is a finite number (i.e., not infinite or not a number), and `false
` otherwise.<?php
$num = 123.45;
if (is_finite($num)) {
echo "$num is a finite number";
} else {
echo "$num is not a finite number";
}
?>
123.45 is a finite number
$num
` is assigned the value `123.45
`. The `if
` statement checks if `$num
` is finite using the `is_finite()
` function. $num
` is a finite number, the message "123.45 is a finite number" will be printed.is_infinite()
` function, on the other hand, returns `true
` if the given value is infinite, and `false
` otherwise.<?php
$num = INF;
if (is_infinite($num)) {
echo "$num is infinite";
} else {
echo "$num is not infinite";
}
?>
INF is infinite
$num
` is assigned the value `INF
`, which represents infinity. The `if
` statement checks if `$num
` is infinite using the `is_infinite()
` function. If `$num
` is infinite, the message "INF is infinite" will be printed.is_finite()
` and `is_infinite()
` functions will return `false`.