Using PHP, what would be the best way to convert a Plain Text List to an Associative Array.
The Plain Text List stucture looks like this:
Item 1
Item 1 > Sub Item 1.1
Item 1 > Sub Item 1.2
Item 2
Item 2 > Sub Item 2.1 > Sub Sub Item 2.1.1
Item 2 > Sub Item 2.1 > Sub Sub Item 2.1.2
Item 2 > Sub Item 2.1 > Sub Sub Item 2.1.2 > Sub Sub Sub Item 2.1.2.1
Item 2 > Sub Item 2.2 > Sub Sub Item 2.2.1
Item 2 > Sub Item 2.2 > Sub Sub Item 2.2.2
Item 3
Item 4
Item 4 > Sub Item 4.1
The function / method would not be limited to a specific depth.
The desired array would look something like this:
$array['Item 1']['Sub Item 1.1'];
$array['Item 1']['Sub Item 1.2'];
$array['Item 2']['Sub Item 2.1'];
$array['Item 2']['Sub Item 2.1']['Sub Sub Item 2.1.1'];
$array['Item 2']['Sub Item 2.1']['Sub Sub Item 2.1.2'];
$array['Item 2']['Sub Item 2.1']['Sub Sub Item 2.1.2']['Sub Sub Sub Item 2.1.2.1'];
$array['Item 2']['Sub Item 2.2']['Sub Sub Item 2.2.1'];
$array['Item 2']['Sub Item 2.2']['Sub Sub Item 2.2.2'];
$array['Item 3'];
$array['Item 4'];
$array['Item 4']['Sub Item 4.1'];
Im not sure if this is the best array stucture to adopt.
On the UI Side...
The array will be used to populate a series of heirachal drop down lists through jQuery.ajax, where the contents of the child list is dependant on the parent selection.
User selects Item 2, a new list appears with the Sub Items, if they select Sub Sub Item 2.1.2 for instance, then a third list appears with Sub Sub Sub Item 2.1.2.1 as it's only option.
I can do all the jQuery stuff, its just the PHP function that is causing me a headache !
I included an explanation of what I wated to do with the array incase it influences the way the function(s) is(are) written.