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?

解决方案

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

"" (an empty string)

0 (0 as an integer)

"0" (0 as a string)

NULL

FALSE

array() (an empty array)

var $var; (a variable declared, but without a value in a class)

So take the example below:

$arr = array(

'ele1' => 'test',

'ele2' => false

);

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) $arr['ele2'] is set, but empty. So:

isset($arr['ele2']) === true && empty($arr['ele2']) === true

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值