PHP menu & submenu items created by arrays

prowebinteractiveinc
prowebinteractiveinc used Ask the Experts™
on
Im building a menu in a website admin portal for many ecommerce websites, therefore I have the menu items header to be the site name, underneath I want the links that correspond to the site, menu headers and links are in arrays as show below. I dont know if this was the right way to go about this but mySiteMenuItemsArray array is for placing the menu items in the right site so obviously the code shows that all the links shown would go under SITE1.COM
$showMyMenu = "";
	$cssTop = 0;
	$cssLineSpacer = 45;
	$btCntr = 1;	
	$sitesCntr = 0;
	
	$inlineCss = "height:30px; width:145px left:0px; z-index:2; background-image:url(../img/bk_bts_menu.gif); background-repeat:no-repeat; padding-left: 10px; padding-top:0px;";
	
	$sitesMenu = array("SITE1.NET", "SITE2.COM", "SITE3.COM", "SITE4.COM");
	$mySiteMenuItemsArray = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
	$myMenuItemsArray = array("Configuration", "Shipping Config", "Referrals (0)", "Orders (" . $displayOrdersNum . ")", "Payments", "Refunds", "Customers", "Coupons", "Categories", "Inventory", "System Errors", "States & Provinces");
	$myMenuUrlsArray = array("config.php", "shippingConfig.php", "referrals.php", "orders.php", "payments.php", "refunds.php", "clients.php", "coupons.php", "categories.php", "inventory.php", "systemErrors.php", "statesProvinces.php");	

	// MENU HEADER
	for($sm=0; $sm < sizeof($sitesMenu); $sm++)
	{	
		#********** CSS **********#
		$inlineCss .= "top: " . $cssTop . "px;";
		#********** CSS **********#

		$showMyMenu .= "<div style=\"" . $inlineCss . "\" id=\"bt_" . $sitesCntr . "\">" . $sitesMenu[$sm] . "</div>" . chr(13);
		$sitesCntr ++;
		$cssTop = $cssTop + $cssLineSpacer;	

	
// SHOW MENU ITEMS HERE

	}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
line 15:, try

for($sm=0; $sm < count($sitesMenu); $sm++)

Commented:
Your question is unclear. What do you want to ask or seeking support for?
I have 4 sites SITE 1, SITE 2, SITE 3, SITE 4,  The illustrated version of what I want is BELOW
links that are in a particular site category correspond with each other
##### SITE 1 #####
LINK 1
LINK 2
LINK 3

##### SITE 2 #####
LINK 1
LINK 2

##### SITE 3 #####
LINK 1
LINK 2
LINK 3
LINK 4
LINK 5
Commented:
Hi,

I think you need to re-arrange your menu array as follow.

$menus[0] => array{	'title' => 'SITE 1',
					'sublinks' => array(
			                           array( 'title'=>'Configuration', 'link'=>'config.php'),
                                       array( 'title'=>'Shipping Config', 'link'=>'shippingConfig.php'),
                                       array( 'title'=>'Referrals (0)', 'link'=>'referrals.php')
                                       ))
$menus[1] => array{	'title' => 'SITE 2',
                    'sublinks' => array( ))
$menus[2] => array{	'title' => 'SITE 3',
                    'sublinks' => array( ))
$menus[3] => array{	'title' => 'SITE 4',
                    'sublinks' => array( ))

// Loop through menu as follows

       // MENU HEADER
        foreach($menus as $menu){
			
			//  HTML for header from $menu['title']
			
			foreach($menu['sublinks'] as $sublink){
			
				/**
				 *   menu link from $menu['link'] and title from $menu['title']
				 */
			}
			
		}

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial