examples/AdWords/v201809/AccountManagement/GetAccountHierarchy.php
private static function printAccountHierarchy(
        $account,
        $customerIdsToAccounts,
        $customerIdsToChildLinks,
        $depth = null
    ) {
        if ($depth === null) {
            print "(Customer ID, Account Name)\n";
            self::printAccountHierarchy(
                $account,
                $customerIdsToAccounts,
                $customerIdsToChildLinks,
                0
            );

            return;
        }

        print str_repeat('-', $depth * 2);
        $customerId = $account->getCustomerId();
        printf("%s, %s\n", $customerId, $account->getName());

        if (array_key_exists($customerId, $customerIdsToChildLinks)) {
            foreach ($customerIdsToChildLinks[strval($customerId)] as $childLink) {
                $childAccount = $customerIdsToAccounts[strval($childLink->getClientCustomerId())];
                self::printAccountHierarchy(
                    $childAccount,
                    $customerIdsToAccounts,
                    $customerIdsToChildLinks,
                    $depth + 1
                );
            }
        }
    }
private static function printAccountHierarchy(
        $account,
        $customerIdsToAccounts,
        $customerIdsToChildLinks,
        $depth = null
    ) {
        if ($depth === null) {
            print "(Customer ID, Account Name)\n";
            self::printAccountHierarchy(
                $account,
                $customerIdsToAccounts,
                $customerIdsToChildLinks,
                0
            );

            return;
        }

        print str_repeat('-', $depth * 2);
        $customerId = $account->getCustomerId();
        printf("%s, %s\n", $customerId, $account->getName());

        if (array_key_exists($customerId, $customerIdsToChildLinks)) {
            foreach ($customerIdsToChildLinks[strval($customerId)] as $childLink) {
                $childAccount = $customerIdsToAccounts[strval($childLink->getClientCustomerId())];
                self::printAccountHierarchy(
                    $childAccount,
                    $customerIdsToAccounts,
                    $customerIdsToChildLinks,
                    $depth + 1
                );
            }
        }
    }
private static function printAccountHierarchy ( $ account , $ customerIdsToAccounts , $ customerIdsToChildLinks , $ depth = null ) { if ( $ depth === null ) { print "(Customer ID, Account Name)\n" ; self :: printAccountHierarchy ( $ account , $ customerIdsToAccounts , $ customerIdsToChildLinks , 0 ) ; return ; } print str_repeat ( '-' , $ depth * 2 ) ; $ customerId = $ account -> getCustomerId ( ) ; printf ( "%s, %s\n" , $ customerId , $ account -> getName ( ) ) ; if ( array_key_exists ( $ customerId , $ customerIdsToChildLinks ) ) { foreach ( $ customerIdsToChildLinks [ strval ( $ customerId ) ] as $ childLink ) { $ childAccount = $ customerIdsToAccounts [ strval ( $ childLink -> getClientCustomerId ( ) ) ] ; self :: printAccountHierarchy ( $ childAccount , $ customerIdsToAccounts , $ customerIdsToChildLinks , $ depth + 1 ) ; } } }
Prints the specified account's hierarchy using recursion.

@param ManagedCustomer $account the account to print
@param array $customerIdsToAccounts a map from customer IDs to accounts
@param array $customerIdsToChildLinks a map from customer IDs to child
links
@param int|null $depth the current depth we are printing from in the
account hierarchy; i.e., how far we've recursed
Prints the specified account s hierarchy using recursion .