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

前端 未结 3 1332
野趣味
野趣味 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:32

    If you wanted to check to see if all of the values where populated you can use

     if(call_user_func_array("isset", $array['foo']['bar']))
    

    For what you want to do though you could use array reduce with a closure

     if(array_reduce($array, function(&$res, $a){if ($a) $res = true;}))
    

    Note this will only work in php 5.3+

提交回复
热议问题