You had the right idea with recursivity. What you could do is check if the current element is an array, and if it is, you call the function with that array again until you find an element that is not an array. You could return this element in another array that would recursively get filled with non empty values.
i've created this simple function that work for your example. It won't work if you have multiple element like this one in your arrays.
<?php
// example code
$array = [
[
[
[
'some key' => 'some value'
]
]
]
];
function recursivelyRemoveTechnicallyNotEmptyArray($array) {
// this will keep the value that are not emtpy
$arrayWithValue = [];
// in our case. the first case can be 0 or "some key". We need to take care of both cases.
$firstkey = array_keys($array)[0];
// if the first element is an array, we do a recursive call with that element
if(is_array($array[$firstkey])) {
// we append the result of the recursive call to the current return value.
$arrayWithValue = array_merge($arrayWithValue, recursivelyRemoveTechnicallyNotEmptyArray($array[$firstkey]));
} else {
// it is not an array, we push it into what we are going to return
$arrayWithValue[] = $array[$firstkey];
}
return $arrayWithValue;
}
var_dump(recursivelyRemoveTechnicallyNotEmptyArray($array));
I've also created a playground for you to test.