Note that there are some explanatory texts on larger screens.

plurals
  1. POphp create navigation menu from multidimensional array dynamically
    primarykey
    data
    text
    <p>I did research on this, and wasn't able to find an exact answer. Most of the questions/answers on here pertaining to this seem to be unfinished. If anyone knows of a finished solution similar to my question, please point me in that direction!</p> <p>Here is my array:</p> <pre><code>Array ( ['home'] =&gt; Array ( [0] =&gt; sub-home1 [1] =&gt; sub-home2 ) ['about'] =&gt; Array ( [0] =&gt; sub-about ['about2'] =&gt; Array ( [0] =&gt; sub-sub-about ) ) ['staff'] =&gt; Array ( [0] =&gt; sub-staff1 [1] =&gt; sub-staff2 ) ['contact'] =&gt; contact ) </code></pre> <p>And here is what I would like to turn it into:</p> <pre><code>&lt;ul&gt; &lt;li&gt;&lt;a href=""&gt;home&lt;a/&gt; &lt;ul&gt; &lt;li&gt;&lt;a href=""&gt;sub-home1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;sub-home2&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;about&lt;a/&gt; &lt;ul&gt; &lt;li&gt;&lt;a href=""&gt;sub-about&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;about2&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a href=""&gt;sub-sub-about&lt;a/&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;staff&lt;a/&gt; &lt;ul&gt; &lt;li&gt;&lt;a href=""&gt;sub-staff1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;sub-staff2&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;contact&lt;a/&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>The array will be dynamically generated, but will have a limit of 3 levels ex: about->about2->sub-sub-about. I tried going off of this question: <a href="https://stackoverflow.com/questions/5628722/php-mysql-navigation-menu">PHP/MySQL Navigation Menu</a> but they didn't really seem to come to a conclusion? I am familiar with foreach's whiles and for loops but I just can't seem to wrap my head around this one. </p> <p><strong>EDIT: Enzino, your code works!</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload