如何从这个组数组中删除Array [1],因为它在两个字段中具有空值???。我尝试使用array_chunk和array_filter但没有得到。如果有任何帮助那就太棒!!!!!!
Array
(
[0] => Array
(
[product] => 3
[processing_id] => 33
[quantity] => 50
)
[1] => Array
(
[product] =>
[processing_id] => 33
[quantity] =>
)
)
答案 0 :(得分:0)
$array = array_filter($array, function (array $entry) {
return $entry['product'] && $entry['quantity'];
});
将回调修改为具体条件。仅当product
和quantity
都是 truthy 时才会保留条目。
答案 1 :(得分:0)
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.