有没有一种方法来检查数组中的所有元素是否在php中为null [英] Is there a way to check if all the elements in an array are null in php

查看:61
本文介绍了有没有一种方法来检查数组中的所有元素是否在php中为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以检查PHP中数组中的所有元素是否为空?

Is there a way to check if all the elements in an array are null in PHP?

例如,我有一个数组 array (null,null,null,null)-有没有一种方法可以检查这种情况?

For instance, I have an array array(null,null,null,null) - is there a way to check this scenario?

我正在寻找一种更好的方法,而不仅仅是遍历整个数组并检查每个元素。

I am looking for a better way than just looping through the entire array and checking each element.

推荐答案

进行此工作的另一种简单方法是使用 max()函数。

Another simple way of making this work is to use the max() function.

max(array( 3, 4, null, null  ) )      # is 4
max(array( null, null, null, null)    # is null

因此,您可以发出一个简单的 if(is_null(max($ array))){...} 调用。

Thus you can issue a simple if( is_null(max($array)) ) { ... } call.

这篇关于有没有一种方法来检查数组中的所有元素是否在php中为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆