使用php从数组中的数组中删除空值


Remove empty values from array within array using php

如何从该组数组中删除Array[1],因为它在两个字段中都有空值???。我尝试使用array_chunk和array_filter,但没有得到。如果有任何帮助,那太棒了!!!!!!

Array
    (
        [0] => Array
            (
                [product] => 3
                [processing_id] => 33
                [quantity] => 50
            )
        [1] => Array
            (
                [product] => 
                [processing_id] => 33
                [quantity] => 
            )
    )
$array = array_filter($array, function (array $entry) {
    return $entry['product'] && $entry['quantity'];
});

将回调修改为确切的条件。只有当productquantity都是truthy时,才会保留条目。

array_filter($array)
array_filter: "If no callback is supplied, all entries of input equal to FALSE will be removed." This means that elements with values NULL, 0, '0', '', FALSE, array() will be removed too.
The other option is doing
array_diff($array, array(''))
which will remove elements with values NULL, '' and FALSE.