加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 13:17:24 所属栏目:PHP教程 来源:网络整理
导读:http://php.net/manual/en/function.in-array.php – 有问题,因为它只检查==.这里是否有任何聪明的oneliner可以通过===来做到这一点? 如果数组为空,即有0个元素,或者数组不包含任何完全为null的值,则返回false.如果数组至少有一个=== null元素,则为True. in
http://php.net/manual/en/function.in-array.php – 有问题,因为它只检查==.这里是否有任何聪明的oneliner可以通过===来做到这一点?

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

in_array(null,$haystack,true);

如果您阅读the doc you referenced,您将看到该函数采用可选的第三个参数:

If the third parameter strict is set
to TRUE then the in_array() function
will also check the types of the
needle in the haystack.

这是函数签名,特别是它出现在doc中:

bool in_array ( mixed $needle,array $haystack [,bool $strict = FALSE ] )

Searches haystack for needle using loose comparison unless strict is set.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读