best way to check a empty array?

后端 未结 11 1136
难免孤独
难免孤独 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条回答
  •  悲&欢浪女
    2020-11-30 10:57

    Short circuiting included.

    function hasValues($input, $deepCheck = true) {
        foreach($input as $value) {
            if(is_array($value) && $deepCheck) {
                if($this->hasValues($value, $deepCheck))
                    return true;
            }
            elseif(!empty($value) && !is_array($value))
                return true;
        }
        return false;
    }
    

提交回复
热议问题