Remove lines with empty values from multidimensional-array in php

后端 未结 5 1483
忘了有多久
忘了有多久 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:27

    Try this:

    Note: $arr is your array.

    foreach ( $arr as $key => $line ) {
    
        foreach ( $line as $item ) {
    
            if ( empty( $item ) ) {
    
                unset( $arr[$key] );
                break;
            }
    
        }
    
    }
    

    Cheers

提交回复
热议问题