title: PHP: Generating category/subcategory UL list from array?
body: <p>I have an array filled with "Category" objects, each one containing an id and a parent_id value. They're accessed like this:</p>
  
  <pre><code>$category-&gt;get("id"); //gets category id
  $category-&gt;get("parent_id"); gets parent category id
  </code></pre>
  
  <p>I want to make a HTML UL list like this:</p>
  
  <pre><code>&lt;ul&gt;
      &lt;li&gt;Category&lt;/li&gt;
      &lt;li&gt;Category
          &lt;ul&gt;
              &lt;li&gt;Child Category&lt;/li&gt;
              &lt;li&gt;Child Category&lt;/li&gt;
              &lt;li&gt;Child Category
                  &lt;ul&gt;
                      &lt;li&gt;Child Category&lt;/li&gt;
                      &lt;li&gt;Child Category&lt;/li&gt;
                      &lt;li&gt;Child Category&lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/li&gt;
          &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Category&lt;/li&gt;
      &lt;li&gt;Category&lt;/li&gt;
      &lt;li&gt;Category&lt;/li&gt;
      &lt;li&gt;Category&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>What sort of loop must be done to generate this?</p>