I have an multidimensional array (key - value), and some values are not set, empty in this case, if so the parent array must be removed from the main array.
The code that I have build only removes the empty key.
In my example the IT & ES language translation keys are empty so we need to removed this parent array.
$results = $arr =array(
[16] => Array
(
[0] => Array
(
[language] => de
[translation] => blog/beer
)
[1] => Array
(
[language] => en
[translation] => blog/some-slug-yeah
)
[2] => Array
(
[language] => es
[translation] =>
)
[3] => Array
(
[language] => fr
[translation] => blog/paris-big-city
)
[4] => Array
(
[language] => it
[translation] =>
)
[5] => Array
(
[language] => nl
[translation] => blog/nederlands-slug
)
)
[...]//more
)
Function to remove keys.
function array_filter_recursive($input){
foreach ($input as &$value){
if (is_array($value)){
$value = array_filter_recursive($value);
}
}
return array_filter($input);
}
$results = array_filter_recursive( $results );