examples/AdManager/v201811/InventoryService/GetAdUnitHierarchy.php
private static function displayInventoryTreeHelper(
        AdUnit $root,
        array $treeMap,
        $depth
    ) {
        $rootId = $root->getId();

        printf(
            "%s%s(%s)%s",
            self::generateTab($depth),
            $root->getName(),
            $rootId,
            PHP_EOL
        );

        if (!array_key_exists($rootId, $treeMap) || empty($treeMap[$rootId])) {
            return;
        }

        foreach ($treeMap[$rootId] as $child) {
            self::displayInventoryTreeHelper($child, $treeMap, $depth + 1);
        }
    }
private static function displayInventoryTreeHelper(
        AdUnit $root,
        array $treeMap,
        $depth
    ) {
        $rootId = $root->getId();

        printf(
            "%s%s(%s)%s",
            self::generateTab($depth),
            $root->getName(),
            $rootId,
            PHP_EOL
        );

        if (!array_key_exists($rootId, $treeMap) || empty($treeMap[$rootId])) {
            return;
        }

        foreach ($treeMap[$rootId] as $child) {
            self::displayInventoryTreeHelper($child, $treeMap, $depth + 1);
        }
    }
private static function displayInventoryTreeHelper ( AdUnit $ root , array $ treeMap , $ depth ) { $ rootId = $ root -> getId ( ) ; printf ( "%s%s(%s)%s" , self :: generateTab ( $ depth ) , $ root -> getName ( ) , $ rootId , PHP_EOL ) ; if ( ! array_key_exists ( $ rootId , $ treeMap ) || empty ( $ treeMap [ $ rootId ] ) ) { return ; } foreach ( $ treeMap [ $ rootId ] as $ child ) { self :: displayInventoryTreeHelper ( $ child , $ treeMap , $ depth + 1 ) ; } }
Helper for displaying inventory units.

@param AdUnit $root the root ad unit to build a subtree
@param array $treeMap associative array mapping each ad unit to its
children
@param int $depth the depth the tree has reached
Helper for displaying inventory units .