Andy11548 Posted July 7, 2011 Share Posted July 7, 2011 Hello, I'm trying to make 2 arrays with a connection to each other and I want them to loop together so that the arrays are connected. $page_title = array('Home', 'About Us', 'Members'); $page_link = array('index', 'about', 'members'); I want them to automatically convert it so it's like: <a href="index.php">Home</a> || <a href="about.php">About Us</a> || <a href="members.php">Members</a> How could I make it so that it automatically makes it like that, from arrays? If there is a way, or another way which is simular, help would be greatly appriciated. Thanks, Andy. Quote Link to comment Share on other sites More sharing options...
gizmola Posted July 7, 2011 Share Posted July 7, 2011 You have 2 options: a key'd array where you pick one or the other to be the key, or just an array of arrays. Since I don't see you accessing this array by keys, I'm just going to show you the array of arrays. Something like this should work: $menu = array(array('title' => 'Home', 'link' => 'index'), array('title' => 'About Us', 'link' => 'about'), array('title' => 'Members', 'link' => 'members')); // make your links $menuhtml = ''; foreach ($menu as $menuitem) { $menuhtml .= '' . $menuitem['title'] . ' ||'; } echo rtrim($menuhtml, '|'); Quote Link to comment Share on other sites More sharing options...
Andy11548 Posted July 7, 2011 Author Share Posted July 7, 2011 Thank you very, very much. This is exactly what I was looking for. I'll have to revise and write the method to make sure that I remember it. You have a been a great help and I thank you alot. Thanks again, Andy. Quote Link to comment 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.