public function flatify(Node $node, &$flatArray = NULL) { if ($flatArray === NULL) { $flatArray = []; } $flatArray[] = $node; if (!$node->hasChildren()) { return $flatArray; } foreach ($node->getChildren() as $child) { $this->flatify($child, $flatArray); } return $flatArray; }