public static function asHierarchy(array $array): array
    {
        $hierarchy = [];

        foreach ($array as $key => $value) {
            $segments = explode('.', (string) $key);
            $valueSegment = array_pop($segments);
            $branch = &$hierarchy;

            foreach ($segments as $segment) {
                if (! isset($branch[$segment])) {
                    $branch[$segment] = [];
                }

                $branch = &$branch[$segment];
            }

            $branch[$valueSegment] = $value;
        }

        return $hierarchy;
    }