examples/AdManager/v201811/InventoryService/GetAdUnitHierarchy.php
private static function buildAndDisplayAdUnitTree(
        AdUnit $root,
        array $adUnits
    ) {
        if (is_null($root)) {
            print "No root unit found.\n";

            return;
        }

        $treeMap = [];

        foreach ($adUnits as $adUnit) {
            $parentId = $adUnit->getParentId();

            if (!is_null($parentId)) {
                if (!array_key_exists($parentId, $treeMap)) {
                    $treeMap[$parentId] = [];
                }

                $treeMap[$parentId][] = $adUnit;
            }
        }

        self::displayInventoryTree($root, $treeMap);
    }
private static function buildAndDisplayAdUnitTree(
        AdUnit $root,
        array $adUnits
    ) {
        if (is_null($root)) {
            print "No root unit found.\n";

            return;
        }

        $treeMap = [];

        foreach ($adUnits as $adUnit) {
            $parentId = $adUnit->getParentId();

            if (!is_null($parentId)) {
                if (!array_key_exists($parentId, $treeMap)) {
                    $treeMap[$parentId] = [];
                }

                $treeMap[$parentId][] = $adUnit;
            }
        }

        self::displayInventoryTree($root, $treeMap);
    }
private static function buildAndDisplayAdUnitTree ( AdUnit $ root , array $ adUnits ) { if ( is_null ( $ root ) ) { print "No root unit found.\n" ; return ; } $ treeMap = [ ] ; foreach ( $ adUnits as $ adUnit ) { $ parentId = $ adUnit -> getParentId ( ) ; if ( ! is_null ( $ parentId ) ) { if ( ! array_key_exists ( $ parentId , $ treeMap ) ) { $ treeMap [ $ parentId ] = [ ] ; } $ treeMap [ $ parentId ] [ ] = $ adUnit ; } } self :: displayInventoryTree ( $ root , $ treeMap ) ; }
Builds and displays an ad unit tree from ad units underneath
the root ad unit.

@param AdUnit $root the root ad unit to build the tree under
@param AdUnit[] $adUnits the ad units under the root
Builds and displays an ad unit tree from ad units underneath the root ad unit .