http://php.net/manual/en/function.in-array.php - 有问题,因为它只检查==
.这里有没有聪明的oneliner可以做到===
吗?
如果数组为空,即有0个元素,或者数组不包含任何完全为null的值,则返回false.如果数组至少有一个=== null
元素,则为真.
小智 23
in_array(null, $haystack, true);
Run Code Online (Sandbox Code Playgroud)
如果您阅读了引用的文档,您将看到该函数采用可选的第三个参数:
如果第三个参数strict设置为TRUE,那么in_array()函数也将检查haystack中针的类型.
这是函数签名,特别是它出现在doc中:
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
Searches haystack for needle using loose comparison unless strict is set.
Run Code Online (Sandbox Code Playgroud)
in_array函数接受将执行===比较的第三个参数(严格)
in_array(null, $array, true);
Run Code Online (Sandbox Code Playgroud)