I have searched a bit on SO and haven't been able to find this unique use case, but maybe I don't know how to phrase it. I am looking to use a PHP array (see format below) to build a dynamic HTML menu that duplicates identical string values into sub menus when a match exists.
This may be too complicated but I would like to find out if it is possible and if someone has a code sample. I don't mind changing the 'verse' array value structure to make it more mutable and get this to work (perhaps turning it into array since there are 1:many potential values in it.)
I could not get the HTML below to format quite right for SO but the gist of the request is that all articles with a matching book/chapter string would get placed together and nested. If there are 2 entries for Psalms 121 (which there are in the below array), then they should be nested together in the same sub-menu.
Desired End Structure (Note that because 2 strings matched Psalms chapter 121, they were combined together:
Hebrews
Chapter 12
Verse 26-28
Chapter 9
Verse 23-24
Psalms
Chapter 121
Verse 3-4
Verse 7-10
Chapter 16
Verse 11
Exodus
Chapter 33
Verse 14
Thank you in advance for your help!
PHP Array:
<?php
$articles = array(
array(
'contentid' => '109',
'full' => 'Song by Artist (Ref 109)',
'verse' => 'Hebrews 12:26-28'),
array(
'contentid' => '110',
'full' => 'Song by Artist (Ref 110)',
'verse' => 'Psalms 121:3-4'),
array(
'contentid' => '111',
'full' => 'Song by Artist (Ref 111)',
'verse' => 'Hebrews 9:23-24'),
array(
'contentid' => '112',
'full' => 'Song by Artist (Ref 112)',
'verse' => 'Psalms 16:11; Exodus 33:14; Psalms 121:7-10'));
?>
I would like this to draw an HTML menu that looks like this:
<!-- Hebrews -->
<div class="submenu">
<a href="#">**Hebrews**</a>
<!-- Level 2 menu -->
<div>
<div>
<div class="submenu">
<a href="#">Chapter *12*</a>
<!-- Level 3 menu -->
<div>
<div>
<a href="#"><span>Song by Artist (Ref 109)</span>Verse *26-28*</a>
</div>
</div>
</div>
<div class="submenu">
<a href="#">Chapter *9*</a>
<!-- Level 3 menu -->
<div>
<div>
<a href="#"><span>Song by Artist (Ref 111)</span>Verse *23-24*</a>
</div>
</div>
</div>
<!-- Psalms -->
<div class="submenu">
<a href="#">**Psalms**</a>
<!-- Level 2 menu -->
<div>
<div>
<div class="submenu">
<a href="#">Chapter *121*</a>
<!-- Level 3 menu -->
<div>
<div>
<a href="#"><span>Song by Artist (Ref 110)</span>Verse *3-4*</a>
<a href="#"><span>Song by Artist (Ref 112)</span>Verse *7-10*</a> </div>
</div>
</div>
Chapter *9*
Song by Artist (Ref 111)Verse *23-24*