0

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.

  • Does this answer your question? [How to access and manipulate multi-dimensional array by key names / path?](https://stackoverflow.com/questions/27929875/how-to-access-and-manipulate-multi-dimensional-array-by-key-names-path) – CBroe May 19 '22 at 13:04
  • @CBroe was trying using that and [Convert google product taxonomy to multidimensional array](https://stackoverflow.com/questions/25510067/convert-google-product-taxonomy-to-multidimensional-array) but I need to search parent ID so it was stuck. – Wisnu Hendro May 19 '22 at 13:22
  • We can not help you based on nothing more than the info that you are "stuck." Show what you tried then (edit the question), and explain what exactly the problem with it is. – CBroe May 19 '22 at 13:26

0 Answers0