Code: Select all
| id | parent | child1 | child2 | child3 |
--------------------------------------------------
1 | Home | | | |
2 | About | Foo1 | | |
3 | About | Foo2 | | |
4 | About | Foo3 | | |
5 | Resources | Bar1 | | |
6 | Resources | Bar2 | | |
7 | Resources | Bar3 | foo1 | |
8 | Resources | Bar4 | foo2 | |
9 | Services | Zot1 | | |
10 | Services | Zot2 | | |
11 | Services | Zot3 | zam1 | zoo1 |
12 | Services | Zot3 | zam1 | zoo2 |Code: Select all
$menu=array();
$menu["home"]="#";
$menu["about"]=array();
$menu["about"]["foo1"]="#";
$menu["about"]["foo2"]="#";
$menu["about"]["foo3"]="#";
$menu["resources"]["Bar1"]="#";
$menu["resources"]["Bar2"]="#";
$menu["resources"]["Bar3"]=array();
$menu["resources"]["Bar3"]["foo1"]="#";
$menu["resources"]["Bar4"]=array();
$menu["resources"]["Bar4"]["foo2"]="#";The challenge I'm having is successfully detecting when an object is the "last" object in the structure (prompting '= "#"'), and when an object has "child" objects (prompting '=array()').
I've tried:
Code: Select all
while($array = mysql_fetch_array($navResult)){
if(($array['parent'])&&(($array['child1'])==NULL)){
$menu[$array['parent']] = "#";
}elseif(($array['child1'])&&(($array['child2'])==NULL)){
$menu[$array['parent']] = array();
$menu[$array['parent']][$array['child1']] = "#";
}elseif(($array['child2'])&&(($array['child3'])==NULL)){
$menu[$array['parent']] = array();
$menu[$array['parent']][$array['child1']] = array();
$menu[$array['parent']][$array['child1']][$array['child2']] = "#";
}
}Code: Select all
Array
(
[HOME] => #
[ABOUT US] => Array
(
[Foo3] => #
)
[RESOURCES] => Array
(
[Bar4] => Array
(
[foo2] => #
)
)
[SERVICES] => Array
(
[Zot2] => #
)
)thanks. max