检查如果一个数组有一个或多个空值 [英] check if an array have one or more empty values

查看:111
本文介绍了检查如果一个数组有一个或多个空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数组$ var和我想如果阵列中的一个或多个元素都是空的(我的意思是,字符串是)返回FALSE。

我觉得 array_filter()是更好的方式,但我不知道如何将它以这种方式进行筛选。

我该怎么办呢?


解决方案

功能emptyElementExists()

 函数emptyElementExists($ ARR){
  返回array_search(,$ ARR)==假的!;
  }

示例:

  $ VAR =阵列(text1中,,文字3);
后续代码var_dump(emptyElementExists($ VAR));

输出:


  

布尔(真)


参考

I have the array $var, and I'd like to return FALSE if one or more element in the array are empty (I mean, the string are "").

I think that array_filter() is the better way, but I don't know how to filter it in this manner.

How can I do it?

解决方案

function emptyElementExists()

function emptyElementExists($arr) {
  return array_search("", $arr) !== false;
  }

Example:

$var = array( "text1", "", "text3" );
var_dump( emptyElementExists($var) );

Output:

bool(true)

Reference

这篇关于检查如果一个数组有一个或多个空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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