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.
bool is_nan(number)
This function requires the number as a parameter.
This function returns true
(1
) if the value is NaN; otherwise, it returns false
.
The following example shows how to use is_nan()
in PHP.
<?php#numberecho("is_nan(10): ");echo (is_nan(10));echo("\n");echo("is_nan(-5.3): ");echo (is_nan(5.3));echo("\n");?><?php#nanecho("is_nan(0/0): ");echo (is_nan(0/0));echo("\n");echo("is_nan(acos(2)): ");echo (is_nan(acos(2)));?>