php - 检查空数组的最佳方法?

标签 php arrays recursion

我如何像这个例子一样递归地检查数组是否有空内容:

Array
(
    [product_data] => Array
        (
            [0] => Array
                (
                    [title] => 
                    [description] => 
                    [price] => 
                )

        )
    [product_data] => Array
        (
            [1] => Array
                (
                    [title] => 
                    [description] => 
                    [price] => 
                )

        )

)

数组不为空但没有内容。我怎样才能用一个简单的函数来检查这个?

谢谢!!

最佳答案


function is_array_empty($InputVariable)
{
   $Result = true;

   if (is_array($InputVariable) && count($InputVariable) > 0)
   {
      foreach ($InputVariable as $Value)
      {
         $Result = $Result && is_array_empty($Value);
      }
   }
   else
   {
      $Result = empty($InputVariable);
   }

   return $Result;
}

关于php - 检查空数组的最佳方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4014327/

相关文章:

javascript - 如何递归地计算它在对象中出现的目标键(属性)的数量?

php - 使用 php 在 VARCHAR 中查找并替换

c++ - iPhone 应用程序因 C++ 代码而崩溃

c++ - 在 C++ 中为二叉搜索树创建删除函数

algorithm - 整数 数字的平方根

python - pytorch - torch.gather 的倒数

php mysql ajax 实时搜索数组

php - fatal error : Call to a member function format () on boolean

php - 如何使用php和mysql代码在wordpress数据库中插入表单数据

c - 将 addressof 与 2 个数组的 memcpy 结合使用