public static function removeEmptyElementsRecursively(array $array): array
    {
        $result = $array;
        foreach ($result as $key => $value) {
            if (is_array($value)) {
                $result[$key] = self::removeEmptyElementsRecursively($value);
                if ($result[$key] === []) {
                    unset($result[$key]);
                }
            } elseif ($value === null) {
                unset($result[$key]);
            }
        }
        return $result;
    }
public static function removeEmptyElementsRecursively(array $array): array
    {
        $result = $array;
        foreach ($result as $key => $value) {
            if (is_array($value)) {
                $result[$key] = self::removeEmptyElementsRecursively($value);
                if ($result[$key] === []) {
                    unset($result[$key]);
                }
            } elseif ($value === null) {
                unset($result[$key]);
            }
        }
        return $result;
    }
public static function removeEmptyElementsRecursively ( array $ array ) : array { $ result = $ array ; foreach ( $ result as $ key => $ value ) { if ( is_array ( $ value ) ) { $ result [ $ key ] = self :: removeEmptyElementsRecursively ( $ value ) ; if ( $ result [ $ key ] === [ ] ) { unset ( $ result [ $ key ] ) ; } } elseif ( $ value === null ) { unset ( $ result [ $ key ] ) ; } } return $ result ; }
Recursively removes empty array elements.

@param array $array
@return array the modified array
Recursively removes empty array elements .