is_real()函数是PHP中的内置函数,用于检查给定值是否为实数。
用法:
bool is_real( mixed $var )
参数:该函数接受上面提到并在下面描述的一个参数:
$var:它包含需要检查的变量的值。
返回值:如果变量的给定值为实数,则返回TRUE,否则返回FALSE。
程序1:
// PHP code to demonstrate
// the is_real() function
function square($num) {
return (is_real($num));
}
var_dump(square(9.09));
var_dump(square(FALSE));
var_dump(square(14));
var_dump(square(56.30));
?>
输出:
bool(true)
bool(false)
bool(false)
bool(true)
程序2:
// PHP program to demonstrate the
// is_real() function
$variable_name1 = 67.099;
$variable_name2 = 32;
$variable_name3 = "abc";
$variable_name4 = FALSE;
// Check given variable is real number or not
if (is_real($variable_name1))
echo "$variable_name1 is a real value. \n";
else
echo "$variable_name1 is not a real value. \n";
// Check given variable is real number or not
if (is_float($variable_name2))
echo "$variable_name2 is a real value. \n";
else
echo "$variable_name2 is not a real value. \n";
// Check given variable is real number or not
if (is_float($variable_name3))
echo "$variable_name3 is a real value. \n";
else
echo "$variable_name3 is not a real value. \n";
// Check given variable is real number or not
if (is_float($variable_name4))
echo "FALSE is a real value. \n";
else
echo "FALSE is not a real value. \n";
?>
输出:
67.099 is a real value.
32 is not a real value.
abc is not a real value.
FALSE is not a real value.