I've been told that multidimensional arrays offer the best way to do what I'm trying to get here.
I'm building a new site using PHP and I want to have a heirarchical menu structure.
The problem is I'm having trouble getting to the second and third dimension data. I can't work out how to do it.
Here's the basic structure of my menu...
= categories
== links
====sections
Categories *never* have urls in the menu. Only links and sections are clickable menu items.
Sections are only displayed when the current page is either the parent 'link', or another section in the same link.
I'm having trouble just thinking about how to organise my multidimensional array in the first place.
So you could have a menu like this...
Code: Select all
=category1
==link1
====section1
====section2
====section3
==link2
==link3
==link4
====section1
====section2
==link5
====section1
====section2
=category2
==link1
==link2
====section1
==link3
=category3
==link1
==link2
==link3This is how I've got my array structured so far...
Code: Select all
$menu['cat1'] = '';
$menu['cat1']['link1'] = 'http://url';
$menu['cat1']['link2'] = 'http://url';
$menu['cat2'] = '';
$menu['cat2']['link1'] = 'http://url';
$menu['cat2']['link1']['section1'] = 'http://url';
$menu['cat2']['link1']['section2'] = 'http://url';
$menu['cat2']['link1']['section3'] = 'http://url';
$menu['cat2']['link2'] = 'http://url';
$menu['cat2']['link2']['section1'] = 'http://url';
$menu['cat2']['link3'] = 'http://url';
$menu['cat2']['link4'] = 'http://url';
$menu['cat2']['link5'] = 'http://url';
$menu['cat2']['link5']['section1'] = 'http://url';
$menu['cat2']['link5']['section2'] = 'http://url';
$menu['cat2']['link5']['section3'] = 'http://url';
$menu['cat2']['link5']['section4'] = 'http://url';
$menu['cat2']['link5']['section5'] = 'http://url';
$menu['cat3'] = '';
$menu['cat3']['link1'] = 'http://url';
$menu['cat3']['link2'] = 'http://url';
$menu['cat3']['link2']['section1'] = 'http://url';
$menu['cat3']['link2']['section2'] = 'http://url';
$menu['cat3']['link3'] = 'http://url';I know I'll then have to set up a nested loop. Then in the nested loop I will then test to see if the url in the array equals the current page and either display the sections, or not. And highlight the section/link as the current page (in bold or something).
Any advice as to how I need to arrange the array?
I'm so confused now. I've tried setting it up so many different ways then found there are different reasons for setting it up in different ways - and it's become a bit of a nightmare.
I'd like to get it started correctly so I don't have to backtrack later on.
Thanks in advance.
Ben