models/CommentModel.php
protected static function buildTree(&$data, $rootID = 0)
    {
        $tree = [];

        foreach ($data as $id => $node) {
            if ($node->parentId == $rootID) {
                unset($data[$id]);
                $node->children = self::buildTree($data, $node->id);
                $tree[] = $node;
            }
        }

        return $tree;
    }
protected static function buildTree(&$data, $rootID = 0)
    {
        $tree = [];

        foreach ($data as $id => $node) {
            if ($node->parentId == $rootID) {
                unset($data[$id]);
                $node->children = self::buildTree($data, $node->id);
                $tree[] = $node;
            }
        }

        return $tree;
    }
protected static function buildTree ( & $ data , $ rootID = 0 ) { $ tree = [ ] ; foreach ( $ data as $ id => $ node ) { if ( $ node -> parentId == $ rootID ) { unset ( $ data [ $ id ] ) ; $ node -> children = self :: buildTree ( $ data , $ node -> id ) ; $ tree [ ] = $ node ; } } return $ tree ; }
Build comments tree.

@param array $data comments list
@param int $rootID

@return array|ActiveRecord[]
Build comments tree .