best way to check a empty array?

后端 未结 11 1137
难免孤独
难免孤独 2020-11-30 10:16

How can I check an array recursively for empty content like this example:

Array
(
    [product_data] => Array
        (
            [0] => Array
               


        
11条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 11:07

    
    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;
    }
    

提交回复
热议问题