❮ PHP Variable Handling Reference
Example
Check whether a variable is of type float or not:
<?php
$a = 32;
echo "a is " . is_real($a) . "<br>";
$b = 0;
echo "b is " . is_real($b) . "<br>";
$c = 32.5;
echo "c is " . is_real($c) . "<br>";
$d = "32";
echo "d is " .
is_real($d) . "<br>";
$e = true;
echo "e is " . is_real($e) . "<br>";
$f = "null";
echo "f is " . is_real($f) . "<br>";
$g = 1.e3;
echo "g is " . is_real($g) . "<br>";
?>
Try it Yourself »
Definition and Usage
The is_real() function checks whether a variable is of type float or not.
This function is an alias of is_float().
Syntax
Parameter Values
variable | Required. Specifies the variable to check |
Technical Details
TRUE if variable is a float, FALSE otherwise |
Boolean |
4.0+ |
❮ PHP Variable Handling Reference
View Discussion
Improve Article
Save Article
View Discussion
Improve Article
Save Article
The is_real() function is an inbuilt function in PHP which is used to check the given value is a real number or not.
Syntax:
bool is_real( mixed $var )Parameters: This function accepts one parameter as mentioned above and described below:
- $var: It contains the value of variable that need to be check.
Return Value: It returns TRUE if the given value of variable is real number, FALSE otherwise.
Program 1:
<?php
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));
?>
Output:
bool(true) bool(false) bool(false) bool(true)Program 2:
<?php
$variable_name1 = 67.099;
$variable_name2 = 32;
$variable_name3 = "abc";
$variable_name4 = FALSE;
if (is_real($variable_name1))
echo "$variable_name1 is a real value. \n";
else
echo "$variable_name1 is not a real value. \n";
if (is_float($variable_name2))
echo "$variable_name2 is a real value. \n";
else
echo "$variable_name2 is not a real value. \n";
if (is_float($variable_name3))
echo "$variable_name3 is a real value. \n";
else
echo "$variable_name3 is not a real value. \n";
if (is_float($variable_name4))
echo "FALSE is a real value. \n";
else
echo "FALSE is not a real value. \n";
?>
Output:
67.099 is a real value. 32 is not a real value. abc is not a real value. FALSE is not a real value.Reference: //www.php.net/manual/en/function.is-real.php
Submit a Pull Request Report a Bug
(PHP 4, PHP 5, PHP 7, PHP 8)
is_real — Alias of is_float()
Description
This function is an alias of: is_float().
Warning
This alias was DEPRECATED in PHP 7.4.0, and REMOVED as of PHP 8.0.0.
+add a note
User Contributed Notes
There are no user contributed notes for this page.