tsilenzio Posted July 30, 2007 Share Posted July 30, 2007 Is it possible to nest a foreach loop inside another? If so is this done properly then: //<?php // -- Enable Text Highlighting for The Forum -- // $links = array( "Account" => array( "Home" => "index.php", "Login" => "login.php", "Action" => "action.php", "Logout" => "logout.php" ), "Control Panel" => array( "Create" => "create.php", "Delete" => "delete.php", "Ban" => "ban.php", "Unban" => "ban.php?step=unban" ) ); foreach($links as $key => $title) { echo("<p>\n<strong>$title</strong>"); foreach($title as $key2 => $val) { echo("<a href=\"$val\">$key2</a><br />"); } echo("</p>"); } Or somthign similar to that.. if i wrote that right, i didnt test it just wrote it into the textarea on this forum.. Thanks for your help! Link to comment https://forums.phpfreaks.com/topic/62404-nested-foreach/ Share on other sites More sharing options...
cooldude832 Posted July 30, 2007 Share Posted July 30, 2007 looks okay test it out Link to comment https://forums.phpfreaks.com/topic/62404-nested-foreach/#findComment-310598 Share on other sites More sharing options...
Nakor Posted July 30, 2007 Share Posted July 30, 2007 Yep that'll work =) Link to comment https://forums.phpfreaks.com/topic/62404-nested-foreach/#findComment-310691 Share on other sites More sharing options...
clearstatcache Posted July 30, 2007 Share Posted July 30, 2007 dat's ryt...dat'll work.. Link to comment https://forums.phpfreaks.com/topic/62404-nested-foreach/#findComment-310710 Share on other sites More sharing options...
btherl Posted July 30, 2007 Share Posted July 30, 2007 It's fine, except that you should be using $key instead of $title in your first echo. Link to comment https://forums.phpfreaks.com/topic/62404-nested-foreach/#findComment-310711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.