I'm having trouble converting an array into correctly nested HTML. Assuming I have an array with the following example values -
An, Author---Some Book
Another, Author---A Book
Another, Author---Another Book
Be, Author---Book 1
Be, Author---Book 2
No, Author---Book 1
How do turn that into an organised HTML like -
<div>
<div class="letter">A</div>
<div>
<div class="author">An, Author</div>
<div class="title">Some Book</div>
</div>
<div>
<div class="author">Another, Author</div>
<div class="title">A Book</div>
<div class="title">Another Book</div>
</div>
<div>
<div>
<div class="letter">B</div>
<div>
<div class="author">Be, Author</div>
<div class="title">Book 1</div>
<div class="title">Book 2</div>
</div>
<div>
<div>
<div class="letter">N</div>
<div>
<div class="author">No, Author</div>
<div class="title">Book 1</div>
</div>
<div>
I don't have any trouble with PHP, its just I'm not sure how I would organise the data. Split into three different arrays (Letters, Authors, Books) before pulling the data back together? But then how would I associate the books (Letter->Author->Book)?
Thanks for any ideas.