Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Recursive arrays to UL (Logic)
    primarykey
    data
    text
    <p>I'm referring from <a href="https://stackoverflow.com/questions/4903668/convert-array-of-paths-into-ul-list">Convert array of paths into UL list</a></p> <p>and i found an helpful answer with this function but from what I'm doing is doesn't work properly as I'm having a MySQL Tables structers with id, parentid, name to be able to make recursive category and sub category.</p> <p>so I'm able to export the data into arrays which is has extra array called CHILDREN has the sub category arrays into it.</p> <p>but when I try to use this function</p> <pre><code>function buildUL($array) { echo "\n&lt;ul&gt;\n"; foreach ($array as $key =&gt; $value) { echo "&lt;li&gt;&lt;a href=\"#\"&gt;"; echo $value['name']; if (is_array($value)) $this-&gt;buildUL($value['children']); echo "&lt;/a&gt;&lt;/li&gt;\n"; } echo "&lt;/ul&gt;\n"; } </code></pre> <p>The problem is that I got multiple output by <ul></ul> as empty and I want to avoid them the output are</p> <pre><code>&lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;A &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;C &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;F &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;test &lt;ul&gt; &lt;/ul&gt; &lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;B &lt;ul&gt; &lt;/ul&gt; &lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;1 &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;2 &lt;ul&gt; &lt;/ul&gt; &lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;3 &lt;ul&gt; &lt;/ul&gt; &lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;99 &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;Another Test &lt;ul&gt; &lt;/ul&gt; &lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;2 X &lt;ul&gt; &lt;/ul&gt; &lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Ham Yum &lt;ul&gt; &lt;/ul&gt; &lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Be You &lt;ul&gt; &lt;/ul&gt; &lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;1 Z &lt;ul&gt; &lt;/ul&gt; &lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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