Recursively remove empty elements and subarrays from a multi-dimensional array

后端 未结 6 2062
暖寄归人
暖寄归人 2020-11-27 19:19

I can\'t seem to find a simple, straight-forward solution to the age-old problem of removing empty elements from arrays in PHP.

My input array may look like this: <

6条回答
  •  一生所求
    2020-11-27 19:49

    Try using array_map() to apply the filter to every array in $array:

    $array = array_map('array_filter', $array);
    $array = array_filter($array);
    

    Demo: http://codepad.org/xfXEeApj

提交回复
热议问题