PHP:检查是否在数组中某一项为空 [英] php: check if certain item in an array is empty

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

问题描述

在PHP中,怎么会检查是否指定的项目(通过名称,我想 - 数将可能也行),数组是空的。

In PHP, how would one check to see if a specified item (by name, I think - number would probably also work) in an array is empty?

推荐答案

空类型(从PHP手册)。以下是认为是空的任何变量:

Types of empty (from PHP Manual). The following are considered empty for any variable:


  • (空字符串)

  • 0(0作为一个整数)

  • 0(0作为一个字符串)

  • NULL

  • FALSE

  • 阵列()(空数组)

  • 变量$ VAR; (一个变量声明,但没有在一个类中的值)

因此​​,采取下面的例子:

So take the example below:

$arr = array(
          'ele1' => 'test',
          'ele2' => false           
       );

1)$改编['ele3']未设置。所以:

使用isset($改编['ele3'])===假放;&安培;空($改编['ele3'])===真

未设置而空。空()检查变量是否被设置而空,或者没有。

1) $arr['ele3'] is not set. So:
isset($arr['ele3']) === false && empty($arr['ele3']) === true
it is not set and empty. empty() checks for whether the variable is set and empty or not.

2)$改编['ele2']设置,而空。所以:

使用isset($改编['ele2'])===真放;&安培;空($改编['ele2'])===真

2) $arr['ele2'] is set, but empty. So:
isset($arr['ele2']) === true && empty($arr['ele2']) === true

1)$改编['ELE1']设置,而不是空:

使用isset($改编['ELE1'])===真放;&安培;空($改编['ELE1'])===虚假

1) $arr['ele1'] is set and not empty:
isset($arr['ele1']) === true && empty($arr['ele1']) === false

如果你想检查是否是空的,只是使用空()函数。

if you wish to check whether is it empty, simply use the empty() function.

这篇关于PHP:检查是否在数组中某一项为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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