I have a menu being built via a multi-dimensional array. A current item is set by matching its url attribute with the current request. I want this value to bubble up to its parents, but I can't for the life of me get it working - I'm sure I've been close, but it's proving a bit tricky. Here's the array:
Array
(
[children] => Array
(
[Home] => Array
(
[url] => /
)
[The Challenge] => Array
(
[url] => /challenge
)
[The Finish] => Array
(
[url] => /finish
)
[Latest News] => Array
(
[url] => /latest_news
)
[Participants] => Array
(
[url] => /participants
[children] => Array
(
[Some guy] => Array
(
[url] => /participants/some_guy
[children] => Array
(
[Hats] => Array
(
[url] => /participants/some_guy/hats
[current] => 1
Essentially, I'm looking for a function that will iterate through every item until it finds the [current] flag, then propagate that value back up to its parents. There are no set limits on depth in the menu.
For the example above, it would result in:
Array
(
[children] => Array
(
[Home] => Array
(
[url] => /
)
[The Challenge] => Array
(
[url] => /challenge
)
[The Finish] => Array
(
[url] => /finish
)
[Latest News] => Array
(
[url] => /latest_news
)
[Participants] => Array
(
[url] => /participants
[current] => 1
[children] => Array
(
[Some guy] => Array
(
[url] => /participants/some_guy
[current] => 1
[children] => Array
(
[Hats] => Array
(
[url] => /participants/some_guy/hats
[current] => 1