Open In App

PHP | is_real() Function

Last Updated : 27 Apr, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
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
<?php 
// 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));

?> 
Output:
bool(true)
bool(false)
bool(false)
bool(true)
Program 2: php
<?php 
// 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"; 
?> 
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: https://www.php.net/manual/en/function.is-real.php

Next Article

Similar Reads