is_nan() : whether a value is not a number
PHP Math
echo is_nan(4); // Return False
echo "<br>";
echo is_nan(4.78); // Return False
echo "<br>";
echo is_nan(0); // Return False
echo "<br>";
echo is_nan(acos(2)); // Output is True
Syntax
bool is_nan ( float $input )
Parameter DESCRIPTION
$input Required : Number to check.
The output is TRUE if $input is 'not a number', else False.
We can check a input or variable is a number or not by using is_nan function. Note that we can't check a string with this function.
We can check square root of a negative number with is_nan() function. Here is a sample code to check.
$v = acos(1.1);
if(is_nan($v)){
echo "this is not a number";
}else{
echo "this is a number";
}
Output is here. More about acos()
this is not a number
You can change the line $v=acos(1.1) with different values of variable $v and see the result.
$v=5.23; // this is a number
$v=4; // this is a number
Getting the output by using var_dump()
echo var_dump(is_nan(4)); // bool(false)
echo "<br>";
echo var_dump(is_nan(4.78)); // bool(false)
echo "<br>";
echo var_dump(is_nan(0)); // bool(false)
echo "<br>";
echo var_dump(is_nan(acos(2))); // bool(true)
Questions
What does the is_nan()
function in PHP do?
What is the purpose of the is_nan()
function in PHP?
What is the return value of the is_nan()
function?
How can you use the is_nan()
function to check if a variable contains a NaN (Not a Number) value?
What are some examples of values that would return true
when passed to the is_nan()
function?
How does the is_nan()
function differ from the isNaN()
function in JavaScript?
Can you use the is_nan()
function to check if a string is a valid number?
How can you handle scenarios where a mathematical operation in PHP may result in a NaN value?
Are there any alternative approaches to check if a value is NaN without using the is_nan()
function?
Is the is_nan()
function limited to specific data types, or can it work with different types of variables?
← Math Functions
base_convert(): Convert number From any base to other →
decbin() Binary equivalent of decimal number →
dechex(): Convert decimal number to hexadecimal system →
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com