title: PHP Format Multidimensional Object as Select Drop Down with Depth
body: <p>How can I take the following and echo it as a beautiful formatted select drop down including '--' for each level?</p>
  
  <pre><code>Array
  (
      [0] =&gt; stdClass Object
          (
              [id] =&gt; 2
              [user_id] =&gt; 6
              [title] =&gt; First Category
              [parent_id] =&gt; 0
          )
  
      [1] =&gt; stdClass Object
          (
              [id] =&gt; 4
              [user_id] =&gt; 6
              [title] =&gt; HTML Times
              [parent_id] =&gt; 0
          )
  
      [2] =&gt; stdClass Object
          (
              [id] =&gt; 5
              [user_id] =&gt; 6
              [title] =&gt; Email Ninja
              [parent_id] =&gt; 0
          )
  
      [3] =&gt; stdClass Object
          (
              [id] =&gt; 6
              [user_id] =&gt; 6
              [title] =&gt; Taco Night
              [parent_id] =&gt; 0
          )
  
      [4] =&gt; stdClass Object
          (
              [id] =&gt; 7
              [user_id] =&gt; 6
              [title] =&gt; SSH
              [parent_id] =&gt; 0
              [childs] =&gt; Array
                  (
                      [0] =&gt; stdClass Object
                          (
                              [id] =&gt; 10
                              [user_id] =&gt; 6
                              [title] =&gt; Root Commands
                              [parent_id] =&gt; 7
                          )
  
                      [1] =&gt; stdClass Object
                          (
                              [id] =&gt; 11
                              [user_id] =&gt; 6
                              [title] =&gt; Shell
                              [parent_id] =&gt; 7
                          )
  
                      [2] =&gt; stdClass Object
                          (
                              [id] =&gt; 12
                              [user_id] =&gt; 6
                              [title] =&gt; Linux
                              [parent_id] =&gt; 7
                          )
  
                      [3] =&gt; stdClass Object
                          (
                              [id] =&gt; 13
                              [user_id] =&gt; 6
                              [title] =&gt; Windows
                              [parent_id] =&gt; 7
                          )
  
                  )
  
          )
  
      [5] =&gt; stdClass Object
          (
              [id] =&gt; 8
              [user_id] =&gt; 6
              [title] =&gt; Dinner Tonight
              [parent_id] =&gt; 0
              [childs] =&gt; Array
                  (
                      [0] =&gt; stdClass Object
                          (
                              [id] =&gt; 9
                              [user_id] =&gt; 6
                              [title] =&gt; Mexican
                              [parent_id] =&gt; 8
                              [childs] =&gt; Array
                                  (
                                      [0] =&gt; stdClass Object
                                          (
                                              [id] =&gt; 14
                                              [user_id] =&gt; 6
                                              [title] =&gt; Tacos
                                              [parent_id] =&gt; 9
                                          )
  
                                  )
  
                          )
  
                  )
  
          )
  
  )
  </code></pre>
  
  <p>I know this topic is pretty heavily covered, but it's not making a whole lot of since to me. After two days of reading... and reading... and reading... I was finally able to get this data out of my database. Now, I can't seem to get it to echo out any deeper than the first category. </p>
  
  <p>Thanks for the assistance and patience. </p>
  
  <p>Here's how I'm getting the parents currently:</p>
  
  <blockquote>
    <p>$level = 0;</p>
    
    <p>$categories = $this->mycrate->build_categories();</p>
  
  <pre><code>    echo '&lt;select class="input-block-level"&gt;';
  
      function RecursiveWrite($categories) {
          foreach ($categories as $category) {
              echo '&lt;option value="'.$category-&gt;id.'"&gt;'.$category-&gt;title.'&lt;/option&gt;';
              RecursiveWrite($category-&gt;parent_id);
          }
      }
  
      RecursiveWrite($categories);
  
      echo '&lt;/select&gt;';
  </code></pre>
  </blockquote>