如何在不循环的情况下检查数组是否具有===null的值


how to check if an array has value that === null without looping?

http://php.net/manual/en/function.in-array.php-有问题,因为它只通过==进行检查。这里有没有聪明的oneliner可以通过===做到这一点?

也就是说,如果数组为空,即有0个元素,或者数组不包含任何完全为null的值,则返回false。如果数组至少有一个=== null元素,则为True。

in_array(null, $haystack, true);

如果你阅读了你引用的文档,你会发现该函数采用了可选的第三个参数:

如果设置了第三个参数strict如果为TRUE,则in_array((函数还将检查大海捞针。

以下是函数签名,具体如文档中所示:

bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
Searches haystack for needle using loose comparison unless strict is set.

in_array函数接受第三个参数(strict(,该参数将执行===比较

in_array(null, $array, true);