There are a few actions not allowed in mathematics. One is that you can not divide by zero. Another is that you can not take the square root of a negative number.

In some areas of mathematics, these rules may be broken (the square root of negative one is called the “imaginary number”) but for your everyday stuff, doing these things produce a special type in PHP known as NAN - Not A Number.

This function will let you know if you have such a case. Remember, this won’t tell you if the value is numeric or not, just if it’s the special type NAN.

$arr = array(1,
             0,
             true,
             false,
             -1,
             M_PI,
             sqrt(-1));
$res = array();
 
foreach($arr as $n) {
  $res[] = is_nan($n);
}			 
var_export($res);
/*
array (
  0 => false,
  1 => false,
  2 => false,
  3 => false,
  4 => false,
  5 => false,
  6 => true,
)
*/