Indented list to multidimensional array

前端 未结 4 692
后悔当初
后悔当初 2020-12-06 08:21

I was surprised not to find an answer to this on SO (or elsewhere on the internet for that matter). It concerns a nested indented list which I want to convert into a multidi

4条回答
  •  无人及你
    2020-12-06 09:19

    I'm not going to write the recursive function, but to point you in a helpful direction, take a look at PHP's substr_count function. Based on this, you could count the number of tabs in front of each line and compare it with the number of tabs in the previous line to figure out if it's a child, sibling, etc.

提交回复
热议问题