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. Link to comment https://forums.phpfreaks.com/topic/241285-arrays-loops/ 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, '|'); Link to comment https://forums.phpfreaks.com/topic/241285-arrays-loops/#findComment-1239387 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. Link to comment https://forums.phpfreaks.com/topic/241285-arrays-loops/#findComment-1239391 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.