ShoeLace1291 Posted February 27, 2008 Share Posted February 27, 2008 I have an array that I am trying to use to display links more easily so I can add a bullet in between them, but I can't figure out the syntax. This is my code: if($result['accnt_found']){ $link = array( 'link1href' => "index.php", 'link1name' => '', $board['name'], ' Home', 'link2href' => "logout.php", 'link2name' => "Logout", 'link3href' => "profile.php", 'link3name' => "My Profile", 'link4href' => "members.php", 'link4name' => "Members", 'link5href' => "events.php", 'link5name' => "index.php?act=events", 'link6href' => "index.php?act=help", 'link6name' => "Help" ); $button = array( 'link1' => '<a href="'$link['link1href']'" name="'$link['link1name']'">Index</a>', 'link2' => '<a href="'$link['link2href']'" name="'$link['link2name']'">Logout</a>', 'link3' => '<a href="'$link['link3href']'" name="'$link['link3name']'">Profile</a>', 'link4' => '<a href="'$link['link4href']'" name="'$link['link4name']'">Members</a>', 'link5' => '<a href="'$link['link5href']'" name="'$link['link5name']'">Events</a>', 'link6' => '<a href="'$link['link6href']'" name="'$link['link6name']'">Help</a>' ); echo ' ', implode(' • ', $buttons) ,' '; } Link to comment https://forums.phpfreaks.com/topic/93413-php-link-array/ Share on other sites More sharing options...
redarrow Posted February 27, 2008 Share Posted February 27, 2008 <?php $l=array("button1"=>"http://www.google.com","button2"=>"http://www.msn.com","button3"=>"http://www.utube.com"); foreach($l as $buttons => $links){ echo"<a href='$links'><br>$buttons</br></a>"; } ?> Link to comment https://forums.phpfreaks.com/topic/93413-php-link-array/#findComment-478577 Share on other sites More sharing options...
ShoeLace1291 Posted February 27, 2008 Author Share Posted February 27, 2008 Can't I just use implode instead of br? I want a bullet, not a body row... lol. Link to comment https://forums.phpfreaks.com/topic/93413-php-link-array/#findComment-478606 Share on other sites More sharing options...
redarrow Posted February 27, 2008 Share Posted February 27, 2008 like this <?php $l=array("button1"=>"http://www.google.com","button2"=>"http://www.msn.com","button3"=>"http://www.utube.com"); foreach($l as $buttons => $links){ echo"<a href='$links'><br><ul><li>$buttons</li></ul></br></a>"; } ?> Link to comment https://forums.phpfreaks.com/topic/93413-php-link-array/#findComment-478610 Share on other sites More sharing options...
ShoeLace1291 Posted February 28, 2008 Author Share Posted February 28, 2008 $array = array("<a href='index.php'>Home</a>", "<a href='login.php'>Login</a>", "<a href='register.php'>Register</a>", "<a href='index.php?act=faq'>Help</a>"); foreach($array as $buttons => $links){ echo "<a href='$links'>$buttons</a> "; } That's my current code. Displays as this: Home'>0 Login'>1 Register'>2 Help'>3 Home, Login, Register, and Help are links like they should be, but '>0, '>1, etc shouldn't be there... Any thoughts? Link to comment https://forums.phpfreaks.com/topic/93413-php-link-array/#findComment-479559 Share on other sites More sharing options...
ShoeLace1291 Posted March 1, 2008 Author Share Posted March 1, 2008 I can't seem to figure this out... Link to comment https://forums.phpfreaks.com/topic/93413-php-link-array/#findComment-480655 Share on other sites More sharing options...
trq Posted March 1, 2008 Share Posted March 1, 2008 Its quite simple. <?php $arr = array('foo' => 'foo.php','bar' => 'bar.php'); foreach ($arr as $k =>$v) { echo "<a href='$k'>$v</a></br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/93413-php-link-array/#findComment-480657 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.