public static function parseHeaders(string $headers): array
    {
        $parsedHeaders = array();

        foreach (explode("\n", $headers) as $header) {
            @list($headerTitle, $headerValue) = explode(':', $header, 2);

            if (!isset($headerValue)) {
                continue;
            }

            $headerTitle = self::processKey(trim($headerTitle));
            $headerValue = trim($headerValue);

            if (!isset($parsedHeaders[$headerTitle])) {
                $parsedHeaders[$headerTitle] = $headerValue;
            } else {
                $parsedHeaders[$headerTitle] .= ", $headerValue";
            }
        }

        return $parsedHeaders;
    }
public static function parseHeaders(string $headers): array
    {
        $parsedHeaders = array();

        foreach (explode("\n", $headers) as $header) {
            @list($headerTitle, $headerValue) = explode(':', $header, 2);

            if (!isset($headerValue)) {
                continue;
            }

            $headerTitle = self::processKey(trim($headerTitle));
            $headerValue = trim($headerValue);

            if (!isset($parsedHeaders[$headerTitle])) {
                $parsedHeaders[$headerTitle] = $headerValue;
            } else {
                $parsedHeaders[$headerTitle] .= ", $headerValue";
            }
        }

        return $parsedHeaders;
    }
public static function parseHeaders ( string $ headers ) : array { $ parsedHeaders = array ( ) ; foreach ( explode ( "\n" , $ headers ) as $ header ) { @ list ( $ headerTitle , $ headerValue ) = explode ( ':' , $ header , 2 ) ; if ( ! isset ( $ headerValue ) ) { continue ; } $ headerTitle = self :: processKey ( trim ( $ headerTitle ) ) ; $ headerValue = trim ( $ headerValue ) ; if ( ! isset ( $ parsedHeaders [ $ headerTitle ] ) ) { $ parsedHeaders [ $ headerTitle ] = $ headerValue ; } else { $ parsedHeaders [ $ headerTitle ] .= ", $headerValue" ; } } return $ parsedHeaders ; }
Parse headers string into associative array. Only named headers returned

Duplicated headers are parsed into comma-separated string:
@link https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
@link https://stackoverflow.com/questions/4371328/are-duplicate-http-response-headers-acceptable
@link https://stackoverflow.com/questions/6368574/how-to-get-the-functionality-of-http-parse-headers-without-pecl

@param string $headers

@return array
Parse headers string into associative array . Only named headers returned