Skip to content

Message: withAddedHeader Example

Terry L edited this page Jun 20, 2020 · 3 revisions

Shieldon\Psr7\Message

withAddedHeader($name, $value)

Return an instance with the specified header appended with the given value.

  • param string name * Case-insensitive header field name.
  • param string|array value * Header value(s)
  • return static

Existing values for the specified header will be maintained. The new value(s) will be appended to the existing list. If the header did not exist previously, it will be added.

Example:

$message = $message->withHeader('foo', 'bar');

echo $message->getHeaderLine('foo');
// Outputs: bar

$message = $message->withAddedHeader('foo', 'baz');
echo $message->getHeaderLine('foo');
// Outputs: bar

$message = $message->withAddedHeader('foo2', 'baz');
echo $message->getHeaderLine('foo2');
// Outputs: baz
Clone this wiki locally