title: Loop for displaying multidimensional PHP array WITHOUT echoing
body: <p>I am trying to build a <code>&lt;ul&gt;</code> tree to display a multidimensional PHP array, but all  of the examples I've seen involve echoing the output from within the for/foreach loop. I would like instead for the output of the recursive function to be stored in a variable without being echoed right away. Is this possible?</p>
  
  <p>My code for the recursive display:</p>
  
  <pre><code>function displayArrayRecursively($tree) {       
      for($i = 0; $i &lt; count($tree); $i++) {
          echo '&lt;ul&gt;&lt;li&gt;'.$tree[$i]['name'];
          if(is_array($tree[$i]['children'])){                    
              $this-&gt;displayArrayRecursively($tree[$i]['children']);
          }
          echo '&lt;/li&gt;&lt;/ul&gt;';
      }
  }
  </code></pre>
  
  <p>But of course, that is echoing the output, which is not what I want. Any ideas? Thanks!</p>