I have this data (columns are depth, name, value, the order is correct):
0, id, 12
0, name, Name
0, pages,
1, 0, Page 1
1, 1, Page 2
1, 2, Page 3
0, items,
1, 0,
2, id, 4
2, title, Example Items
And I’m trying to produce an array structure like this from it:
Array
(
[id] => 12
[name] => Name
[pages] => Array
(
[0] => Page 1
[1] => Page 1
[2] => Page 1
)
[items] => Array
(
[0] => Array
(
[id] => 4
[title] => Example Item
)
)
)
Every attempt I’ve tried so far has failed, I just cant seem to get my head round the logic. Any help would be appreciated. Thanks.
You can accomplish this with a bit of reference trickery. If you have your CSV input converted into a list like:
Then you can traverse it like:
At least works for your example: