Help with tricky php code...

Status
This thread has been locked.

TechEdison

Web Developer
Premium
Feedback score
14
Posts
428
Reactions
177
Resources
0
I like to consider myself a skilled PHP dev, and this is definitely the first time I've had to ask this sort of question.

I'm having an issue with some code that I wrote. There isn't a much better way to describe it than to share exactly what it's doing and what it's supposed to do.

Not looking to pay, as this is probably a stupid 1 line fix that I'm just too sleep deprived to see.

The array the code reads from:

PHP:
$forum = array(
       
                "1" => array(
               
                        "name" => "Example Category",
                        "desc" => "This is an example category",
                        "forums" => array(
                       
                                "1" => array(
                               
                                        "name" => "Example Forum",
                                        "desc" => "This is an example forum",
                                        "perm" => "all"
                               
                                ),
                                "2" => array(
                               
                                        "name" => "Example Protected Forum",
                                        "desc" => "This forum can be written on by admin only",
                                        "perm" => "admin"
                               
                                )
                       
                        )
               
                ),
                "2" => array(
               
                        "name" => "Example Category",
                        "desc" => "This is an example category",
                        "forums" => array(
                       
                                "1" => array(
                               
                                        "name" => "Example Forum",
                                        "desc" => "This is an example forum",
                                        "perm" => "all"
                               
                                ),
                                "2" => array(
                               
                                        "name" => "Example Protected Forum",
                                        "desc" => "This forum can be written on by admin only",
                                        "perm" => "admin"
                               
                                )
                       
                        )
               
                )
       
        );

Code:
PHP:
                                        foreach($forum as $catkey => $cat)
                                        {
                                                $name = $cat["name"];
                                                $desc = $cat["desc"];
                                                $forums = $forum[$catkey]["forums"];
                                               
                                                echo "<B><A HREF='index.php?".$url_login."c=$catkey'>$name</A></B><BR>$desc<BR><BR><PRE>";
                                               
                                                foreach($forums as $forumkey => $forum)
                                                {
                                               
                                                        $name = $forum["name"];
                                                        $desc = $forum["desc"];
                                                        $perm = $fourm["perm"];
                                                       
                                                        echo "    <A HREF='index.php?".$url_login."c=$catkey&f=$forumkey'>$name</A> Perm: $perm<BR>    $desc<BR>    $smallhr";
                                               
                                                }
                                               
                                                echo "</PRE><BR>".$medhr;
                                        }

Result:
unknown.png


As you can see, it loops through the array for the categories fine, but the nested foreach loop that loops through the forums only loops once. Obviously, it is supposed to loop twice (once per category).

You can see the live results at http://www.nocss.ml/forum
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

TechEdison

Web Developer
Premium
Feedback score
14
Posts
428
Reactions
177
Resources
0
Ignore any variables that don't exist, this was taken from the middle of a big file.[DOUBLEPOST=1523497063][/DOUBLEPOST]Nevermind... Fixed by dropping all my weird return functions for the $forum array.
 
Last edited:
Status
This thread has been locked.
Top