PHP Function Reference

PHP is_real() Function



The PHP is_real() function checks whether a variable is of type float. The function returns true if the variable is a float, otherwise it returns false. This function is an alias of is_float() function.

Note: To check whether a variable is a number or a numeric string (such as form input, which is always a string), use is_numeric() function.

Note: This function is DEPRECATED in PHP 7.4.0, and REMOVED as of PHP 8.0.0.

Syntax

is_real(variable)

Parameters

variable Required. Specify the variable being evaluated.

Return Value

Returns true if variable is a float, false otherwise.

Example:

The example below shows the usage of is_real() function.

<?php
var_dump(is_real(10.5));  //returns: bool(true)
var_dump(is_real(1e5));   //returns: bool(true)
  //scientific Notation

echo "\n";

var_dump(is_real('10.5'));  //returns: bool(false)
var_dump(is_real(10));      //returns: bool(false)
var_dump(is_real('10'));    //returns: bool(false)
var_dump(is_real('xyz'));   //returns: bool(false)
var_dump(is_real('1e5'));   //returns: bool(false)
var_dump(is_real(true));    //returns: bool(false)
?>

The output of the above code will be:

bool(true)
bool(true)

bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)

Example:

Consider one more example where this function is used to check all elements of an array whether they are of type float or not.

<?php
$Arr = array(10, "10", 10.5, "10.5", null, 
            false, "true", 1e3, "1e3"); 

foreach ($Arr as $value) {
  echo "is_real(";
  var_export($value);
  echo ") = ";
  var_dump(is_real($value));
}
?>

The output of the above code will be:

is_real(10) = bool(false)
is_real('10') = bool(false)
is_real(10.5) = bool(true)
is_real('10.5') = bool(false)
is_real(NULL) = bool(false)
is_real(false) = bool(false)
is_real('true') = bool(false)
is_real(1000.0) = bool(true)
is_real('1e3') = bool(false)

❮ PHP Variable Handling Reference