protected function buildEnvironmentTree(array $environments, $parent = null)
    {
        $children = [];
        foreach ($environments as $environment) {
            // Root nodes are both the environments whose parent is null, and
            // environments whose parent does not exist.
            if ($environment->parent === $parent
                || ($parent === null && !isset($environments[$environment->parent]))) {
                $this->children[$environment->id] = $this->buildEnvironmentTree(
                    $environments,
                    $environment->id
                );
                $children[$environment->id] = $environment;
            }
        }

        return $children;
    }
protected function buildEnvironmentTree(array $environments, $parent = null)
    {
        $children = [];
        foreach ($environments as $environment) {
            // Root nodes are both the environments whose parent is null, and
            // environments whose parent does not exist.
            if ($environment->parent === $parent
                || ($parent === null && !isset($environments[$environment->parent]))) {
                $this->children[$environment->id] = $this->buildEnvironmentTree(
                    $environments,
                    $environment->id
                );
                $children[$environment->id] = $environment;
            }
        }

        return $children;
    }
protected function buildEnvironmentTree ( array $ environments , $ parent = null ) { $ children = [ ] ; foreach ( $ environments as $ environment ) { // Root nodes are both the environments whose parent is null, and // environments whose parent does not exist. if ( $ environment -> parent === $ parent || ( $ parent === null && ! isset ( $ environments [ $ environment -> parent ] ) ) ) { $ this -> children [ $ environment -> id ] = $ this -> buildEnvironmentTree ( $ environments , $ environment -> id ) ; $ children [ $ environment -> id ] = $ environment ; } } return $ children ; }
Build a tree out of a list of environments.

@param Environment[] $environments The list of environments, keyed by ID.
@param string|null   $parent       The parent environment for which to
build a tree.

@return Environment[] A list of the children of $parent, keyed by ID.
Children of all environments are stored in the
property $this->children.
Build a tree out of a list of environments .