Jump to content

3 dimensional array guidance.


tymlls05

Recommended Posts

I have just taken over a website from a previous designer/host. He was using javascript to generate the menu you see on the left hand side of Allisonlacy.com (please take a look. it is a simple menu and will not take long to load or find.)

 

The array generated to create this menu is:

 

Array ( 
[0] => Array ( 
		[0] => Array ( 
				[kei] => 60
				[parent] => 0
				[lpos] => 1 
				[name] => Home 
				[url] => index.php 
				)
		[1] => Array ( 
				[kei] => 61 
				[parent] => 0 
				[lpos] => 2 
				[name] => About Us 
				[url] => page.php?kei=24 
				) 
		[2] => Array ( 
				[kei] => 72 
				[parent] => 0 
				[lpos] => 3 
				[name] => Agents 
				[url] => staff.php 
				) 
		[3] => Array ( 
				[kei] => 83 
				[parent] => 0 
				[lpos] => 4 
				[name] => 
				Sell A Home 
				[url] => # 
				) 
		[4] => Array ( 
				[kei] => 85 
				[parent] => 0 
				[lpos] => 5 
				[name] => Buy A Home 
				[url] => # ) 
		[5] => Array ( 
				[kei] => 66 
				[parent] => 0 
				[lpos] => 6 
				[name] => Search Listings 
				[url] => idx.php?newsearch=true 
				) 
		[6] => Array ( 
				[kei] => 64 
				[parent] => 0 
				[lpos] => 7 
				[name] => Commercial 
				[url] => idx.php?format=4&offset=0 
				) 
		[7] => Array ( 
				[kei] => 65 
				[parent] => 0 
				[lpos] => 8 
				[name] => Land 
				[url] => idx.php?format=3&offset=0 
				) 
		[8] => Array ( 
				[kei] => 68 
				[parent] => 0 
				[lpos] => 9 
				[name] => Photos 
				[url] => nimbus.php ) 
		[9] => Array ( [kei] => 69 
				[parent] => 0 
				[lpos] => 10 
				[name] => Links 
				[url] => links.php 
				) 
		[10] => Array ( 
				[kei] => 70 
				[parent] => 0 
				[lpos] => 11 
				[name] => Contact Us 
				[url] => page.php?kei=23 
				) 
		[11] => Array ( 
				[kei] => 73 
				[parent] => 0 
				[lpos] => 12 
				[name] => Careers 
				[url] => page.php?kei=120 
				) 
		[12] => Array ( 
				[kei] => 88 
				[parent] => 0 
				[lpos] => 13 
				[name] => Agent Login 
				[url] => http://agents.allisonlacy.com 
				) 
		) 
[73] => Array ( 
		[0] => Array ( 
				[kei] => 74 
				[parent] => 73 
				[lpos] => 0 
				[name] => Licensing 
				[url] => page.php?kei=27 
				) 
		[1] => Array ( 
				[kei] => 81 
				[parent] => 73 
				[lpos] => 1 
				[name] => Is Real Estate For You? 
				[url] => page.php?kei=28 
				) 
		[2] => Array ( 
				[kei] => 77 
				[parent] => 73 
				[lpos] => 2 
				[name] => Why Allison-Lacy? 
				[url] => page.php?kei=38 
				) 
		[3] => Array ( 
				[kei] => 90 
				[parent] => 73 
				[lpos] => 3 
				[name] => All About Allison-Lacy 
				[url] => page.php?kei=120 
				) 
		[4] => Array ( 
				[kei] => 89 
				[parent] => 73 
				[lpos] => 4 
				[name] => Preparing for Your Interview 
				[url] => page.php?kei=106 
				) 
		[5] => Array ( 
				[kei] => 80 
				[parent] => 73 
				[lpos] => 5 
				[name] => Contact Us 
				[url] => page.php?kei=23 
				) 
		[6] => Array ( 
				[kei] => 87 
				[parent] => 73 
				[lpos] => 6 
				[name] => Referral Program 
				[url] => page.php?kei=30 
				) 
		) 
[83] => Array ( 
		[0] => Array ( 
				[kei] => 84 
				[parent] => 83 
				[lpos] => 0 
				[name] => Homeseller Tips 
				[url] => page.php?kei=32 
				) 
		[1] => Array ( 
				[kei] => 62 
				[parent] => 83 
				[lpos] => 1 
				[name] => Properties Search 
				[url] => idx.php?format=1&offset=0 
				) 
		) 
	[85] => Array ( 
		[0] => Array ( 
				[kei] => 63 
				[parent] => 85 
				[lpos] => 5 
				[name] => Properties Search 
				[url] => idx.php?office=40&offset=0 
				)
		)
) 

 

Once the code above is generated is when the javascript steps in and starts generating the menu. I have tried a while and foreach but am just not experienced enough to deal with a three level domain and cross referencing between the levels.

 

Basically the submenus are created where kei==parent. When kei==parent, that kei array is inserted below it's parent.

 

I'm not asking you guys to write the menu code for me, just how to arrange the arrays and correctly order them so I can start adding the coding to regenerate the menu in a more search engine friendly format.

Link to comment
https://forums.phpfreaks.com/topic/164103-3-dimensional-array-guidance/
Share on other sites

If you're just looking to loop through the data, this would do it here:

 

foreach($mainarray AS $parent => $items)
{
// do any parent processing/output stuff here

foreach($items AS $key => $data)
{
	// do any child processing/output stuff here		
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.