src/Common/Traits/Model/Nestable.php
protected function buildTree(array &$aItems, int $iParentId = null): array
    {
        $aTemp         = [];
        $sIdColumn     = $this->getColumn('id');
        $sParentColumn = $this->getColumn('parent_id', 'parent_id');
        foreach ($aItems as $oItem) {
            if ($oItem->{$sParentColumn} == $iParentId) {
                $oItem->children = $this->buildTree($aItems, $oItem->{$sIdColumn});
                $aTemp[]         = $oItem;
            }
        }

        return $aTemp;
    }
protected function buildTree(array &$aItems, int $iParentId = null): array
    {
        $aTemp         = [];
        $sIdColumn     = $this->getColumn('id');
        $sParentColumn = $this->getColumn('parent_id', 'parent_id');
        foreach ($aItems as $oItem) {
            if ($oItem->{$sParentColumn} == $iParentId) {
                $oItem->children = $this->buildTree($aItems, $oItem->{$sIdColumn});
                $aTemp[]         = $oItem;
            }
        }

        return $aTemp;
    }
protected function buildTree ( array & $ aItems , int $ iParentId = null ) : array { $ aTemp = [ ] ; $ sIdColumn = $ this -> getColumn ( 'id' ) ; $ sParentColumn = $ this -> getColumn ( 'parent_id' , 'parent_id' ) ; foreach ( $ aItems as $ oItem ) { if ( $ oItem -> { $ sParentColumn } == $ iParentId ) { $ oItem -> children = $ this -> buildTree ( $ aItems , $ oItem -> { $ sIdColumn } ) ; $ aTemp [ ] = $ oItem ; } } return $ aTemp ; }
Builds a tree of objects

@param array $aItems    The items to sort
@param int   $iParentId The parent ID to sort on

@return array
Builds a tree of objects