Example 1 — Detect NAN
Check NAN, a normal number and an invalid square root.
<?php
echo var_export(is_nan(NAN), true) . PHP_EOL;
echo var_export(is_nan(5.5), true) . PHP_EOL;
echo var_export(is_nan(sqrt(-1)), true) . PHP_EOL; How It Works
- NAN is a built-in constant that means not a number, so the result is true.
- 5.5 is a valid number, so the result is false.
- sqrt(-1) has no real answer, so PHP returns NAN and is_nan() returns true.
- var_export(..., true) turns the boolean into printable text.

