Indented list to multidimensional array

前端 未结 4 687
后悔当初
后悔当初 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:03

    As it's still unclear if you're trying to read from some given structure (html-dom) or from the given string as plain text, I assumed it's the string you're trying to parse. If so, try:

     $key) {
          if (!isset($parent[$key])) {
            $parent[$line] = array();
            break;
          }
    
          $parent =& $parent[$key];
        }
      }
    
      // return
      return $result;
    }
    
    print_r(helper($list));
    

    Demo: http://codepad.org/zgfHvkBV

提交回复
热议问题