如何检查,如果阵列中的所有按键都在PHP空值? [英] How do i check if all keys in an array have empty values in PHP?

查看:107
本文介绍了如何检查,如果阵列中的所有按键都在PHP空值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组

  $阵列=阵列('键1'=>空键2'=>空,KEY3'=>空,KEY4'=> NULL);

我想,以确定是否所有的数组键空值,这样的话返回false。上述实施例应该返回假,因为它不具有任何值。但是,如果一个或多个键具有任何值,则它应该返回真例如下面的例子是真实的。

  $阵列=阵列('键1','键2'=>值2,KEY3','KEY4'=>值4);


解决方案

假设你真正的意思是像

数组

 阵列('键1'=>空键2'=>空,KEY3'=>空,KEY4'=>空)

的答案很简单

 如果(!array_filter($阵列)){
    //所有值都是空的(这里的空是指== FALSE)
}

I have an array

$array = array('key1' => null, 'key2' => null, 'key3' => null, 'key4' => null);

i would like to determine if all the array keys have empty values if so then return false. the above example should return false as it does not have any value. but if one or more keys have any values then it should return true for example the below example is true.

$array = array('key1', 'key2' => value2, 'key3', 'key4' => value4);

解决方案

Assuming you actually mean an array like

array('key1' => null, 'key2' => null, 'key3' => null, 'key4' => null)

the answer is simply

if (!array_filter($array)) {
    // all values are empty (where "empty" means == false)
}

这篇关于如何检查,如果阵列中的所有按键都在PHP空值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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