I am trying to build a multidimensional array from two arrays. The use case is to build a dynamic menu.
Array #1 contains the titles for the menu where any title prefixed with -- will be a 'main' title and any title prefixed with - will be a sub for the previous 'main' title.
For instance, if we have a hypothetical scenario like:
--Home
--About
-Our Philosophy
-The Company
--Careers
-Job List
-Apply
--Contact
Array #2 contains the links for each menu item.
The first step was to combine both arrays into a hash by doing combined = Hash[titles.zip(links).
How would I build it so that I can then loop over and build the menu dynamically?
Looking for a final similar structure to this (unless there's another suggested way):
['Home' => 'http://stackoverflow.com/'],
['About' => 'http://stackoverflow.com/',
[
'Our Philosophy' => 'http://stackoverflow.com/',
'The Company' => 'http://stackoverflow.com/'
]
]
etc...
If someone could explain how to then iterate over it, that would be awesome.
Hash, nor anArray. It is invalid structure.titlesandlinks?