RecursiveIteratorIterator and RecursiveDirectoryIterator to nested html lists

后端 未结 2 1608
执笔经年
执笔经年 2020-12-03 15:57

Here\'s my php script:



        
2条回答
  •  借酒劲吻你
    2020-12-03 16:37

    Store the depth in a variable and check if the variable has been increased or decreased each loop?

    If the depth has been increased, you add another

      tag and if it has been decreased you add a closing
    tag.

    Each loop would always output the

  • tags to wrap the filename.

    e.g.

    $depth = 0;
    foreach ($objects as $name => $object) {
        $depth2 = $objects->getDepth();
        if($depth2 > $depth) { echo '
      '; } echo "
    • " . $object->getFilename() . "
    • "; if($depth2 < $depth) { echo '
    '; } $depth = $depth2; }

    That would need some additional testing and modification to suit your existing code, but hopefully it gives you some ideas.

提交回复
热议问题