Comparing NAN

<?php

//echo acos(3);
var_dump(acos(3) === acos(3));
var_dump(acos(3) == acos(3));

// Note that NAN is a float and becomes 0
var_dump($array = [acos(3) => 3]);
var_dump(isset($array[acos(3)]));

// Idem pour INF, which is infinity
var_dump($array = [INF => 3]);
var_dump(isset($array[INF]));

PHP does not compare NAN values: it always fails, even if the source is the same.

Depending on the context, NAN becomes the string 'NAN', or the integer 0.

Since PHP 8.1, the engine emits a warning to signal it: this is good, and helps spotting such mistakes.

And, in the end, no one uses NAN anyway.

See Also

PHP Features

Last updated: 14 July 2026