is_nan() : whether a value is not a number

Check specifically for NAN

is_nan() checks whether a floating-point value is the special NAN (not-a-number) value. It is not a general numeric-input validator.

$value = sqrt(-1);
var_dump(is_nan($value)); // bool(true)

Use is_nan() only for the special floating-point NAN value; use is_numeric() when validating numeric strings or general input.

var_dump(is_nan(4.0));              // bool(false)
var_dump(is_nan(4.78));             // bool(false)
var_dump(is_nan(acos(2)));          // bool(true)
Syntax
bool is_nan(float $num)
ParameterDESCRIPTION
$numRequired: float value to check.
Returns true only when the float is NAN; otherwise it returns false.

is_nan() is not a general numeric validator. It is intended for floating-point results such as sqrt(-1) or acos(2) that produce NAN.

$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<br>
$v=4; // this is a number
Getting the output by using var_dump()
var_dump(is_nan(4.0));             // bool(false)
var_dump(is_nan(sqrt(-1)));       // bool(true)

Questions


Math Functions is_finite(): check finite values is_infinite(): check infinity


Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer