I have created a category tree where each category contains sub-categories and each category contains its associated content. Some of the categories in this tree contain sub-categories but have no associated content. How can I clean up the category tree so that the tree structure contains only categories that have associated content, or that have sub-categories that have associated content? That is, in the category tree only paths should exist that lead to a category that has associated content.
The structure I have is an array:
[uid_of_category]
=> (array)content
=> empty
=> (array)sub_categories
=> [uid_of_category]
=> (array)content
=> empty
=> (array)sub_categories
=> [uid_of_category]
=> (array)content
=> [...associated content...]
=> (array)sub_categories
[uid_of_category]
=> (array)content
=> empty
=> (array)sub_categories
=> [uid_of_category]
=> (array)content
=> [...associated content...]
=> (array)sub_categories
=> [uid_of_category]
=> (array)content
=> empty
=> (array)sub_categories
=> [uid_of_category]
=> (array)content
=> [...associated content...]
=> (array)sub_categories
...
I tried to use a recursive function to get down to the lowest elements of the tree, but I don't know how to implement that even those elements remain in the tree that have no associated content, but whose sub-element has associated content.