How to check if a multidimensional array is empty or not?

前端 未结 6 1248
[愿得一人]
[愿得一人] 2021-02-01 05:20

Basically, I have a multidimensional array, and I need to check whether or not it is simply empty, or not.

I currently have an if statement trying to do thi

6条回答
  •  梦如初夏
    2021-02-01 05:57

    Combine array_filter() and array_map() for result. ( Result Test )

     [],
            '1'=> [
                'question1',
                'answer1',
                'answer2',
                'answer3',
                'answer4'
            ],
            '2'=> [
                'question1',
                'answer1',
                'answer2',
                'answer3',
                'answer4'
            ]
        ];
    
        $arrayEmpty = [
            '0' => [],
            '1' => [
                '1' => '',
                '2' => '',
                '3' => ''
            ]
        ];
    
        $resultData = array_filter(array_map('array_filter', $arrayData));
        $resultEmpty = array_filter(array_map('array_filter', $arrayEmpty));
    
        var_dump('Data', empty($resultData));
        var_dump('Empty', empty($resultEmpty));
    

提交回复
热议问题