PHP Noob here, in over my head.
I have a file listing script that's checking through a directory and producing a series of file paths. They look more or less like this:
2014/1Q/ES/PDFs/141QES_01.pdf
I want to iterate through the list (it's a long list) and construct a nested associative array or object from which I can create an organized file tree with download links. The catch is I don't want my method to be specific to the path structure for this particular site, I want to build it dynamically based on the directory structure in the file paths so I can use this on other sites with similar needs.
$results = array(
'2014' => array(
'1Q' => array(
'ES' => array(
'PDFs' => array(
'141QES_01.pdf',
'141QES_02.pdf',
...
)
),
'SE' => array(
'PDFs' => array(
'141QSE_01.pdf',
'141QSE_02.pdf',
...
)
),
...
),
'2Q' => array(
'ES' => array(
'PDFs' => array(
'141QES_01.pdf',
'141QES_02.pdf',
...
)
),
'SE' => array(
'PDFs' => array(
'141QSE_01.pdf',
'141QSE_02.pdf',
...
)
),
...
)...
),
'2015' => array(
...
)
)
What's killing me is I can explode the paths into an array that contains the exact keys and filename I need, but I can't for the life of me figure out how to inject that flat array into the larger associative array. I'm betting it's a lot simpler than I'm making it, so I could use some wisdom. If I'm being stupid, I don't mind hearing it.