PHP - How to remove empty entries of an array recursively?

前端 未结 6 1146
臣服心动
臣服心动 2020-12-15 22:58

I need to remove empty entries on multilevel arrays. For now I can remove entries with empty sub-arrays, but not empty arrays... confused, so do I... I think the code will h

6条回答
  •  生来不讨喜
    2020-12-15 23:32

    I think this should solve your problem.

    $retArray =array_filter($array, arrayFilter);
    
    function arrayFilter($array) {
         if(!empty($array)) {
             return array_filter($array);
         }
    }
    

提交回复
热议问题