Elgg\Profiler::flattenTree PHP Method

flattenTree() public method

Turn the tree of times into a sorted list
public flattenTree ( array &$list = [], array $tree, string $prefix = '' ) : void
$list array
$tree array Result of buildTree()
$prefix string Prefix of period string. Leave empty.
return void
    public function flattenTree(array &$list = [], array $tree, $prefix = '')
    {
        $is_root = empty($list);
        if (isset($tree['periods'])) {
            foreach ($tree['periods'] as $period) {
                $this->flattenTree($list, $period, "{$prefix}  {$period['name']}");
            }
            unset($tree['periods']);
        }
        $tree['name'] = trim($prefix);
        $list[] = $tree;
        if ($is_root) {
            usort($list, function ($a, $b) {
                if ($a['duration'] == $b['duration']) {
                    return 0;
                }
                return $a['duration'] > $b['duration'] ? -1 : 1;
            });
        }
    }