What is is_nan() in PHP?

The is_nan() function in PHP returns true (1) if the value is NaN; otherwise, it returns false. Some of the operations that can return a NaN include: division by zero, calculating the square root of a negative number, trying to pass an invalid value to an inverse trigonometric function, and the arc cosine of a value that does not lie in the range negative one to one.

Figure 1 shows the visual representation of the is_nan() function.

Figure 1: Visual representation of is_nan() function

Syntax

bool is_nan(number)

Parameter

This function requires the number as a parameter.

Return value

This function returns true (1) if the value is NaN; otherwise, it returns false.

Example

The following example shows how to use is_nan() in PHP.

<?php
#number
echo("is_nan(10): ");
echo (is_nan(10));
echo("\n");
echo("is_nan(-5.3): ");
echo (is_nan(5.3));
echo("\n");
?>
<?php
#nan
echo("is_nan(0/0): ");
echo (is_nan(0/0));
echo("\n");
echo("is_nan(acos(2)): ");
echo (is_nan(acos(2)));
?>

Free Resources