3D-kreativ Posted July 9, 2010 Share Posted July 9, 2010 Hi, I create a menu like this: $wsMenu = Array ( 'start' => '.', 'karta' => '?p=karta', 'bilder' => '?p=bilder', ); foreach($this->iMenu as $key => $value) { $menu .= "<a href='{$value}' class='menu'>{$key}</a> | "; } But I would like to add some 'id' + names into the link and my question is how to put this extra information for each link in the Array() and how would it be in the foreach loop ? Preciate som help! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/207239-question-about-array/ Share on other sites More sharing options...
Adam Posted July 9, 2010 Share Posted July 9, 2010 $this->iMenu .. was that meant to be $wsMenu? I don't understand what you mean by "'id' + names". Could you provide an example of some form to better illustrate? Quote Link to comment https://forums.phpfreaks.com/topic/207239-question-about-array/#findComment-1083513 Share on other sites More sharing options...
3D-kreativ Posted July 9, 2010 Author Share Posted July 9, 2010 The code is from a front- and page control system with classes, so iMenu comes from $wsMenu. I would like to add this to the links: id="start_link" or id="images_link" or id="map_link"....... I hope you understand? Quote Link to comment https://forums.phpfreaks.com/topic/207239-question-about-array/#findComment-1083518 Share on other sites More sharing options...
Adam Posted July 9, 2010 Share Posted July 9, 2010 The code is from a front- and page control system with classes, so iMenu comes from $wsMenu. I'll take your word for it. Try this: $wsMenu = Array ( 'start' => array( 'id=start_link', 'foo=bar', ), 'karta' => '?p=karta', 'bilder' => '?p=bilder', ); foreach($this->iMenu as $text => $href) { if (is_array($href)) { $href = '?' . implode('&', $href); } $menu .= "<a href='{$href}' class='menu'>{$text}</a> | "; } The only problem is it's limited to pages with multiple params starting with "?". You may want to extend it further to allow a prefix link for the params. Quote Link to comment https://forums.phpfreaks.com/topic/207239-question-about-array/#findComment-1083532 Share on other sites More sharing options...
3D-kreativ Posted July 9, 2010 Author Share Posted July 9, 2010 Thanks! But I get error from this code? $wsMenu = Array ( 'start' => array('id=start','.'), 'karta' => array('id=map', 'p=karta') 'bilder' => array('id=buildings', 'p=bilder') ); Could you explain what you mean with "The only problem is it's limited to pages with multiple params starting with "?". You may want to extend it further to allow a prefix link for the params." Quote Link to comment https://forums.phpfreaks.com/topic/207239-question-about-array/#findComment-1083581 Share on other sites More sharing options...
Adam Posted July 9, 2010 Share Posted July 9, 2010 .. What's the error? Wait a minute. Thinking about it, and maybe I'm missing something, but can't you just store the URL with the parameters..? $wsMenu = Array ( 'start' => '?id=start&foo=bar', 'karta' => '?p=karta', 'bilder' => '?p=bilder', ); I'm also a little unsure about what "." is meant to mean? Quote Link to comment https://forums.phpfreaks.com/topic/207239-question-about-array/#findComment-1083584 Share on other sites More sharing options...
3D-kreativ Posted July 9, 2010 Author Share Posted July 9, 2010 Hmmm, I made it really simple. I did like this: $menu .= "<a href='{$href}' class='menu' id='{$text}>{$text}</a> | "; I gave the body ID the same name as in the links. >So now it works! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/207239-question-about-array/#findComment-1083592 Share on other sites More sharing options...
Adam Posted July 9, 2010 Share Posted July 9, 2010 Ahhh, sorry you didn't explain it very clearly. I thought you were referring to an ID parameter. That's easy then: $wsMenu = Array ( 'start' => array( 'href' => '?p=start', 'id' => 'id1' ), 'karta' => array( 'href' => '?p=karta', 'id' => 'id2' ), 'bilder' => array( 'href' => '?p=bilder', 'id' => 'id3' ), ); foreach($this->iMenu as $text => $link) { $menu .= '<a href="'.$link['href'].'" class="menu"'; if (!empty($link['id'])) { $menu .= ' id="'.$link['id'].'"'; } $menu .= '>'.$text.'</a> | '; } Quote Link to comment https://forums.phpfreaks.com/topic/207239-question-about-array/#findComment-1083603 Share on other sites More sharing options...
3D-kreativ Posted July 9, 2010 Author Share Posted July 9, 2010 Nice! I'm going to try this code later! Sorry for my english language! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/207239-question-about-array/#findComment-1083636 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.