Remove lines with empty values from multidimensional-array in php

后端 未结 5 1484
忘了有多久
忘了有多久 2021-01-21 23:50

How do you remove the lines that have empty elements from a multidimensional-array in PHP?

For instance, from:

1: a, b, c, d
2: d, _, b, a
3: a, b, _, _
         


        
5条回答
  •  旧巷少年郎
    2021-01-22 00:36

    I would iterate through a foreach loop myself something like:

     $array)
        {
            $empty_flag = false;
    
            foreach ($array as $key => $val)
            {
                if ($val == '')
                {
                    $empty_flag = true;
                }
            }
    
            if ($empty_flag == true)
            {
                unset($md_array[$key]);
            }
        }
    ?>
    

    There's almost definitely a more efficient way of doing this so anyone else who has a better solution feel free to let me and Alex know.

提交回复
热议问题