I've been looking a lot of answers, but, none of them are working for me:
I have this array under $quantities variable. If i print_r, i got this:
Array
(
[10] => Array
(
[25.00] => 1
)
[9] => Array
(
[30.00] => 3
)
[8] => Array
(
[30.00] => 4
)
[12] => Array
(
[35.00] =>
)
[1] => Array
(
[30.00] =>
)
[2] => Array
(
[30.00] =>
)
)
But, im looking for a way to remove those with empty values like [12] [1] and [2] and keep everything else.
Array
(
[10] => Array
(
[25.00] => 1
)
[9] => Array
(
[30.00] => 3
)
[8] => Array
(
[30.00] => 4
)
)
Thanks. Sorry if this looks kinda simple, im a newbie and i dont know how to do it. Tried a lot of the functions on the official php docs and none of them worked.
I've used this one:
function array_filter_recursive($array, $callback = null) {
foreach ($array as $key => & $value) {
if (is_array($value)) {
$value = array_filter_recursive($value, $callback);
}
else {
if ( ! is_null($callback)) {
if ( ! $callback($value)) {
unset($array[$key]);
}
}
else {
if ( ! (bool) $value) {
unset($array[$key]);
}
}
}
}
unset($value);
return $array;
}
But i get this:
Array ( [10] => Array ( [25.00] => 1 )
[9] => Array
(
[30.00] => 3
)
[8] => Array
(
[30.00] => 4
)
[12] => Array
(
)
[1] => Array
(
)
[2] => Array
(
)
)
Is almost what i want, but, i would like to remove [12] [1] and [2] arrays.