如何在PHP中获取空索引foreach循环

时间:2018-07-18 05:10:22

标签: php arrays

这里我有一个数组,使用此数组,我必须获取index,例如它具有空值或空值,我对其进行了搜索,但是我没有得到预期的答案,请参见下面的内容,我已经发布了我的预期的答案。

  

print_r($ val);

    Array
(
    [id] => 4 A
    [tripID] => 
    [startFrom] => 1
    [limit] => 20
    [cabID] => 
)
  

预期答案

  1. tripID
  2. cabID

2 个答案:

答案 0 :(得分:2)

这应该有帮助-

=Arrayformula(if(or(importrange(H2,"Sheet1!C2:C")="Mosque",
importrange(H2,"Sheet1!C2:C")="Church",
importrange(H2,"Sheet1!C2:C")="Temple"),
proper(query(importrange(H2,"Sheet1!A2:D"), "Select Col3 Where Col1 = 'New' And Col4 = 'Done'")),
lower(query(importrange(H2,"Sheet1!A2:D"),"Select Col3 Where Col1 = 'New' And Col4 = 'Done'"))))

输出

$a = array
(
    'ID' => '4 A',
    'tripID' => '',
    'startFrom' => 1,
    'limit' => 20,
    'cabID' => '',
);
// Filter array if value is  blank or null but not 0
$check = array_filter($a, function($v) {
  return $v == '' || $v == null;
});
// Extract the keys
print_r(array_keys($check));

array_filter()

答案 1 :(得分:0)

此功能应将您带向正确的方向array_filter。请注意,这似乎是一个家庭作业的问题。