Another recursion question.
What I've tried to develop for the past few hours is a function that will let me generate a flat array of the same pages, but with the children having an identifier in front of them, (i.e. "— Sub Page, — — Sub Sub Page, etc").
I have a hierarchical array of pages, with each child page nested inside of their parent page. Here's an example of their output:
Array
(
[0] => Array
(
[id] => 1
[parent_id] => 0
[title] => Parent Page
[children] => Array
(
[0] => Array
(
[id] => 12
[parent_id] => 1
[title] => Another Sub Page
)
[1] => Array
(
[id] => 3
[parent_id] => 1
[title] => Sub Page
[children] => Array
(
[0] => Array
(
[id] => 7
[parent_id] => 3
[title] => Sub Sub Page
)
)
)
)
)
[1] => Array
(
[id] => 8
[parent_id] => 0
[title] => Another Parent Page
)
)
I've been able to get it working until I reach the second level of the recursion and then it's still generating only one —
. I want to make the solution recursive.
What I'm looking for in the final output using the example above is:
Array
(
[1] => Parent Page
[12] => — Another Sub Page
[3] => — Sub Page
[7] => — — Sub Sub Page
[8] => Another Parent Page
)