src/Common/Traits/Model/Nestable.php
protected function flattenTree(array $aItems, &$aOutput = []): array
    {
        foreach ($aItems as $oItem) {
            $aOutput[] = $oItem;
            $this->flattenTree($oItem->children, $aOutput);
            unset($oItem->children);
        }

        return $aOutput;
    }
protected function flattenTree(array $aItems, &$aOutput = []): array
    {
        foreach ($aItems as $oItem) {
            $aOutput[] = $oItem;
            $this->flattenTree($oItem->children, $aOutput);
            unset($oItem->children);
        }

        return $aOutput;
    }
protected function flattenTree ( array $ aItems , & $ aOutput = [ ] ) : array { foreach ( $ aItems as $ oItem ) { $ aOutput [ ] = $ oItem ; $ this -> flattenTree ( $ oItem -> children , $ aOutput ) ; unset ( $ oItem -> children ) ; } return $ aOutput ; }
Flattens a tree of objects

@param array $aItems  The items to flatten
@param array $aOutput The array to write to

@return array
Flattens a tree of objects