I'm trying to create nested unordered list with php loops. I've tried different things but I need your help to improve my code. Let say in this example that I want four levels.
Here is my PHP code :
<ul>
<?php
for($i = 0; $i < 1; $i++): ?>
<li>
<ul>
<?php for($j = 0; $j <2; $j++): ?>
<li>
<ul>
<?php for($k = 0; $k <2; $k++): ?>
<li>
<ul>
<?php for($l = 0; $l <2; $l++): ?>
<li></li>
<?php endfor; ?>
</ul>
</li>
<?php endfor; ?>
</ul>
</li>
<?php endfor; ?>
</ul>
</li>
<?php
endfor;
?>
</ul>
Here is my HTML output :
<ul>
<li>
<ul>
<li>
<ul>
<li>
<ul>
<li></li>
<li></li>
</ul>
</li>
<li>
<ul>
<li></li>
<li></li>
</ul>
</li>
</ul>
</li>
<li>
<ul>
<li>
<ul>
<li></li>
<li></li>
</ul>
</li>
<li>
<ul>
<li></li>
<li></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
Is there a smarter way to do so? I hope so. I would like to know because I aim to define number of levels dynamically and what I've done is not dynamic at all! :)
Thanks a lot for your replies!