Apply array_filter()
on the main array and then once more on the inner elements:
$aryMain = array_filter($aryMain, function($item) {
return array_filter($item, 'strlen');
});
The inner array_filter()
specifically uses strlen()
to determine whether the element is empty; otherwise it would remove '0'
as well.
To determine the emptiness of an array you could also use array_reduce()
:
array_filter($aryMain, function($item) {
return array_reduce($item, function(&$res, $item) {
return $res + strlen($item);
}, 0);
});
Whether that's more efficient is arguable, but it should save some memory :)