Re: RE: Help with my first recursion menu
| From: | Lex Braun | Date: | Sat, 31 Oct 2009 14:04:55 +0000 |
| Subject: | Re: RE: Help with my first recursion menu | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-299544@lists.php.net to get a copy of this message | ||
Hi,
On Wed, Oct 28, 2009 at 5:22 PM, MEM <talofo@gmail.com> wrote:
> I've been told that stack is the way to go, so I'm trying to understand
> the
> following code:
> http://pastebin.com/m5616c88f
> I've commented every line so that any of you could see if I'm interpreting
> something wrong:
>
>
> I have two questions about this code, that hopefully someone on the list
> could explain:
>
> 1)
> Why do we need to remove the last array item? (on line 32):
> array_pop($urlStack);
>
On line 20, $url creates an URL path that includes the $cat path. Once
you've completed iteration on all children of $cat, the url path should no
longer include $cat path, thus it is removed from $urlStack.
>
> 2)
> Why we print the closed tag of the li element, after the recursive call?
> (on
> line 29)
> echo "</li>\n";
>
Line 29 is closing the li element that was opened on line 23 for $cat.
>
>
> Thanks a lot in advance,
> Márcio
>
-Lex