php教程

is_finite

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

is_finite判断是否为有限值

说明

is_finite ( float $val ) : bool

检查 val 是否是是本机平台上浮点数所允许范围中的一个合法的有限值。

参数

val

要检查的值

返回值

如果 val 是本机平台上 PHP 浮点数所允许范围中的一个合法的有限值,则返回 TRUE

参见

User Contributed Notes

Daniel Klein 09-Jul-2017 05:17
(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.

<?php
$finite
= 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
?>

CopyRight © 2008-2022 verySource.Com All Rights reserved. 京ICP备17048824号-1 京公网安备:11010502034788