public function generate($headings)
    {
        /** @var Entry $previous */
        $root = $previous = new RootEntry();
        foreach ($headings as $heading) {
            if ($heading->getLevel() < $previous->getLevel()) {
                $parent = $previous;
                do {
                    $parent = $parent->getParent();
                } while ($heading->getLevel() <= $parent->getLevel() && $parent->getLevel() != 0);

                $parent->addChild($heading);
                $previous = $heading;
                continue;
            }


            if ($heading->getLevel() > $previous->getLevel()) {
                $previous->addChild($heading);
                $previous = $heading;
                continue;
            }

            //if ($heading->getLevel() == $previous->getLevel()) {
            $previous->getParent()->addChild($heading);
            $previous = $heading;
            continue;
            //}
        }

        return $root;
    }
public function generate($headings)
    {
        /** @var Entry $previous */
        $root = $previous = new RootEntry();
        foreach ($headings as $heading) {
            if ($heading->getLevel() < $previous->getLevel()) {
                $parent = $previous;
                do {
                    $parent = $parent->getParent();
                } while ($heading->getLevel() <= $parent->getLevel() && $parent->getLevel() != 0);

                $parent->addChild($heading);
                $previous = $heading;
                continue;
            }


            if ($heading->getLevel() > $previous->getLevel()) {
                $previous->addChild($heading);
                $previous = $heading;
                continue;
            }

            //if ($heading->getLevel() == $previous->getLevel()) {
            $previous->getParent()->addChild($heading);
            $previous = $heading;
            continue;
            //}
        }

        return $root;
    }
public function generate ( $ headings ) { /** @var Entry $previous */ $ root = $ previous = new RootEntry ( ) ; foreach ( $ headings as $ heading ) { if ( $ heading -> getLevel ( ) < $ previous -> getLevel ( ) ) { $ parent = $ previous ; do { $ parent = $ parent -> getParent ( ) ; } while ( $ heading -> getLevel ( ) <= $ parent -> getLevel ( ) && $ parent -> getLevel ( ) != 0 ) ; $ parent -> addChild ( $ heading ) ; $ previous = $ heading ; continue ; } if ( $ heading -> getLevel ( ) > $ previous -> getLevel ( ) ) { $ previous -> addChild ( $ heading ) ; $ previous = $ heading ; continue ; } //if ($heading->getLevel() == $previous->getLevel()) { $ previous -> getParent ( ) -> addChild ( $ heading ) ; $ previous = $ heading ; continue ; //} } return $ root ; }
Make a tree of the list of headings

@param Entry[] $headings
@return RootEntry
Make a tree of the list of headings