I have a menu structure (Drupal) that contains elements representing a menu link. If the menu has a child menu (is the parent of a submenu) it has an array key ‘below’ with a menu item inside with the same structure. In theory this menu could be infinitely deep and the only way that I know how to go through each level is by create a new loop on the item if ‘below’ has anything in it. I know there has to be a more elegant and dynamic way to deal with this. I’m not really looking for a Drupal specific answer as this problem has come up before and I’ve just hacked it together. Thanks for reading!
I have a menu structure (Drupal) that contains elements representing a menu link. If
Share
Without an example of the kind of data you’re working with it’s difficult to give an exact implementation, but the general class of problems you describe is one that can usually be solved with recursion – a function that calls itself.