I\'ve been looking a lot of answers, but none of them are working for me.
This is the data assigned to my $quantities
array:
Array(
This removes all items with null values recursively on multideminsional arrays. Works on PHP >= 5.6. If you want to remove all "empty" values, replace !is_null($value)
with !empty($value)
.
function recursivelyRemoveItemsWithNullValuesFromArray(array $data = []): array
{
$data = array_map(function($value) {
return is_array($value) ? recursivelyRemoveItemsWithNullValuesFromArray($value) : $value;
}, $data);
return array_filter($data, function($value) {
return !is_null($value);
});
}