private static function doCompact(array $array, $integerKeysIncluded = true)
    {
        $result = array();

        foreach ($array as $key => $value) {
            $escapedKey = self::escapeKey($key);
            $extraKeyPath = "";

            while (self::isCompactableArray($value, $integerKeysIncluded)) {
                $nextValue = reset($value);
                $compactKey = key($value);

                $extraKeyPath .= "." . self::escapeKey($compactKey);
                $value = $nextValue;
            }

            $result[$escapedKey . $extraKeyPath] = self::compactValue($value);
        }

        return $result;
    }