public static function collapse(array $array): array
    {
        $newArray = [];

        foreach ($array as $key => $value) {
            if (is_array($value)) {
                // strip any manually added '.'
                if (preg_match('/\./', (string) $key)) {
                    $key = substr($key, 0, -2);
                }

                self::recurseCollapse($value, $newArray, (array) $key);
            } else {
                $newArray[$key] = $value;
            }
        }

        return $newArray;
    }