How to check if a multi-dimensional array only contains empty values?

前端 未结 3 1358
野趣味
野趣味 2021-02-06 19:20

I looked around and can\'t quite find the answer for this, so I\'m wondering if I contain an array such as this..

$array[\'foo\'][\'bar\'][1] = \'\';
$array[\'fo         


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-02-06 19:35

    $array['foo']['bar'] isn't empty because it's actually array(1=>'',2=>'',3=>'',4=>'').

    You would need to do a foreach loop on it to check if it is indeed all empty.

    $arr_empty = true;
    foreach ($array['foo']['bar'] as $arr) {
        if (!empty($arr)) {
            $arr_empty = false;
        }
    }
    //$arr_empty is now true or false based on $array['foo']['bar']
    

提交回复
热议问题