How to properly nest lists in HTML; in which nev tries to code (PHP)
it was only this year I learned that the proper way to nest lists in HTML is
<ul>
<li>Item
<ul><li>Sub-item</li><ul>
</li>
</ul>
and not
<ul>
<li>Item</li>
<ul><li>Sub-item</li></ul>
</ul>
which makes sense and all, but it is making things hard for me because I am trying to write a thing in PHP that generates a table of contents (a list of nested links) from a web page's headings, and I am having a DICKENS of a time. I figured out how to tell it to *start* a nested list, but I am having trouble figuring out how to close the containing </li> tags correctly. Especially in cases where the list goes from, like, <h4> to <h2>. Do I have to, like, nest the LOOPS too?
I do want to figure it out by myself but if anyone has dealt with this particular problem, hints would be welcome!
trying to hint towards the thing
@nev what do you usually do when you want to reuse code?
@noiob none of my code should ever be re-used
(but seriously, I am only just starting to wrap my head around iterating over lists, so this is over my head)
@nev also if you wanna output a lot of html from PHP I'd recommend looking into twig, you'll save yourself a lot of headaches if you write templates instead of code that juggles strings https://twig.symfony.com