Jump to content

Nested ForEach?


tsilenzio

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.