I tried to code small PHP logic to convert structured plain text to multidimensional array. Source of text is on https://www.google.com/basepages/producttype/taxonomy-with-ids.en-US.txt
Let's take a look at line contains this string: 8017 - Apparel & Accessories > Costumes & Accessories > Costume Accessories > Costume Accessory Sets
I want to convert it into json like this:
{
"1":"8017",
"2":"Costume Accessory Sets",
"3":{
"1":"5192",
"2":"Costume Accessories",
"3":{
"1":"184",
"2":"Costumes & Accessories",
"3":{
"1":"166",
"2":"Apparel & Accessories"
}
}
}
}
The greater-sign '>' is delimiter of each path, which we can find the parent ID of ID: 8017 is 5192.
Line: 5192 - Apparel & Accessories > Costumes & Accessories > Costume Accessories
Thus have another parent on ID: 184
184 - Apparel & Accessories > Costumes & Accessories
and iterate to ID: 166
166 - Apparel & Accessories
Just tried it on single iteration and can't make the recursive one. Any help would be thankful.