Flattening array
<p>I have a function which changes an array into the html list (ol/ul). The depth of the array is passed as an argument.</p>

<p>I wanted to do this in just a single function.</p>

<pre><code>for($i = 0; $i &lt; $depth; $i++) {
   foreach($list_array as $li) {
      if(! is_array($li))
      {
         $str .= '&lt;li&gt;' . $li . '&lt;/li&gt;';
      }
   }
}
</code></pre>

<p>This code gives me the first dimension of the array. I'd like to flatten this array every time the <code>$i</code> increments.</p>

<p>Do you have any suggestions that could be helpful?</p>

<p>And yes, I'm aware of <code>array_walk_recursive()</code>, object iterators etc...I'd like to know if there's a simple way to do this task without using any ot those. I can't come up with anything.</p>

<p>And no, this is not any university project where I'm not allowed to use iterators etc.</p>

<p>EDIT:</p>

<pre><code>print_list(array(
   'some first element',
   'some second element',
   array(
      'nested element',
      'another nested element',
      array(
         'something else'
      )
   )
));
</code></pre>

<p>should output something like:</p>

<pre><code>&lt;ul&gt;
   &lt;li&gt;some first element&lt;/li&gt;
   &lt;li&gt;some second element&lt;/li&gt;
   &lt;ul&gt;
      &lt;li&gt;nested element&lt;/li&gt;
      &lt;li&gt;another nested element&lt;/li&gt; // etc
</code></pre>
