/**
 * Displays an account tree, starting at the account and link provided, and
 * recursing to all child accounts.
 * @param Account $account the account to display
 * @param Link $link the link used to reach this account
 * @param array $accounts a map from customerId to account
 * @param array $links a map from customerId to child links
 * @param int $depth the depth of the current account in the tree
 */
function DisplayAccountTree($account, $link, $accounts, $links, $depth)
{
    print str_repeat('-', $depth * 2);
    printf("%s, %s, %s\n", $account->customerId, !empty($link->descriptiveName) ? $link->descriptiveName : $account->login, isset($link) ? $link->typeOfLink : 'N/A');
    if (array_key_exists($account->customerId, $links)) {
        foreach ($links[$account->customerId] as $childLink) {
            $childAccount = $accounts[$childLink->clientId->id];
            DisplayAccountTree($childAccount, $childLink, $accounts, $links, $depth + 1);
        }
    }
}
/**
 * Displays an account tree, starting at the account and link provided, and
 * recursing to all child accounts.
 * @param Account $account the account to display
 * @param Link $link the link used to reach this account
 * @param array $accounts a map from customerId to account
 * @param array $links a map from customerId to child links
 * @param int $depth the depth of the current account in the tree
 */
function DisplayAccountTree($account, $link, $accounts, $links, $depth)
{
    print str_repeat('-', $depth * 2);
    printf("%s, %s\n", $account->customerId, $account->name);
    if (array_key_exists($account->customerId, $links)) {
        foreach ($links[$account->customerId] as $childLink) {
            $childAccount = $accounts[$childLink->clientCustomerId];
            DisplayAccountTree($childAccount, $childLink, $accounts, $links, $depth + 1);
        }
    }
}