I've been trying to create a multi-level ordered list in PHP for some time now. I've tried and have been been searching and everything I've seen has a different data layout than what I have to work with. Most examples pull the data from a database and build the array based on separate columns and, in come cases, columns with depth or parental relationships information. My data is in a path to an SSRS report and can vary from 2 to 3 (or more in the future) levels so I'm not sure how to build the array to work with the function in this question as the structure of the data I have is different form all the examples.
The full example I'm working is attached as array1.php
I'm pulling data from an SSRS report server. The only relevant part of it is the path to the report I have to link. The report name is always the last element in string. There is an additional column called 'Name' but this is simply a duplicate of the last element in the 'Path' data, so it's somewhat redundant anyway.
Data from SSRS report table - column name = "Path"
/Production/Analyst/POS Sales Excel Data Export
/Production/Analyst/STATS Membership Tracking - RAW
/Production/Information Technologies/IT Dashboard DUMMY
/Production/Information Technologies/IT Department
/Production/Membership/Membership Reports/Membership Grid
/Production/Membership/Membership Reports/Membership Grid by SU
/Production/Membership/Membership Reports/Membership Pie Charts
/Production/Membership/Membership Reports/Membership Sum Drill Down
/Production/Membership/Membership Reports/POS Sales By Date and Location
/Production/Membership/Stats/STATS Council Participation
/Production/Membership/Stats/STATS Council SU Summary Adults
/Production/Membership/Stats/STATS Council Summary Adults
/Production/Membership/Stats/STATS Council Troop Summary Adults
/Production/Membership/Stats/STATS Lifetime Stats
/Production/Membership/Stats/STATS Membership Tracking
/Production/Online Training (LMS)/LMS User ID Lookup
/Production/Online Training (LMS)/Manager Training 2014
/Production/Shop/POS Reports/POS Sales By Date and Location
/Production/Shop/Shop Dashboard DUMMY
/Production/SLT Dashboard/OLD Dashboard Membership_Overview
That data would need need to go in a format like that below to work with the function I have. The ID is irrelevant to my purposes since the link to the report is the same as the report name so I would have to change the function to suit. That said, I need to take the path above and turn it into an array like that below.
Array format required:
$nested = Array
1 => Array ('parent' => 0, 'title' => 'Analyst'),
2 => Array ('parent' => 0, 'title' => 'Membership'),
3 => Array ('parent' => 0, 'title' => 'SLT Dashboard'),
4 => Array ('parent' => '1', 'title' => 'POS Sales Excel Data Export'),
5 => Array ('parent' => '1', 'title' => 'STATS Membership Tracking - RAW'),
6 => Array ('parent' => '2', 'title' => 'Membership Dashboard'),
7 => Array ('parent' => '6', 'title' => 'Membership Grid'),
8 => Array ('parent' => '6', 'title' => 'Membership Grid by Service Unit'),
So, how do convert the data I'm working with into an array that will output a format like the snippet above? I've been looking at a lot of sites trying to understand more about arrays - I'm starting to see the light but still need some help in the right direction. Any help would be greatly appreciated.