PHP Variable Handling is_real() Function
The PHP Variable Handling is_real() function is used to check whether a given value is a real number (a floating-point number). A real number has a decimal point, like 3.14 or 2.5. This function helps find out whether a variable has a floating-point value or not. It is useful for executing mathematical calculations.
If the input value is a real number, the function returns TRUE. If the value is not a real number (e.g., an integer, string, or boolean), the function returns false. This function is useful in a variety of programming tasks. But in later versions of PHP is_real() is no longer needed. Instead, use the function is_float().
This alias was DEPRECATED in PHP 7.4.0, and REMOVED as of PHP 8.0.0.
Syntax
Below is the syntax of the PHP Variable Handling is_real() function −
bool is_real( mixed $value )
Parameters
This function accepts $value parameter which is the value that needs to be checked.
Return Value
The is_real() function returns TRUE if the given value is a real number (floating-point number). And it returns FALSE if the value is not a real number.
PHP Version
First introduced in core PHP 4, the is_real() function continues to function easily in PHP 5, PHP 7, and PHP 8.
Example 1
In this example, we are using var_dump() to display the results. The function is executed with a wide range of values, like a floating-point number, a string, an integer, scientific notation and boolean. But, the PHP Variable Handling is_real() function function was deprecated in PHP 7.4 and deleted in PHP 8.0. Instead, use is_float().
<?php
var_dump(is_real(4.01));
var_dump(is_real('ter'));
var_dump(is_real(44));
var_dump(is_real(44.8));
var_dump(is_real(3e7));
var_dump(is_real(false));
?>
Output
Here is the outcome of the following code −
bool(true) bool(false) bool(false) bool(true) bool(true) bool(false)