public function Collection::add

Same name in this branch

Add a value to a key. If a key of the same name has already been added, the key value will be converted into an array and the new value will be pushed to the end of the array.

Parameters

string $key Key to add:

mixed $value Value to add to the key:

Return value

Collection Returns a reference to the object.

1 call to Collection::add()
Collection::merge in drupal/core/vendor/guzzle/common/Guzzle/Common/Collection.php
Add and merge in a Collection or array of key value pair data.

File

drupal/core/vendor/guzzle/common/Guzzle/Common/Collection.php, line 63

Class

Collection
Key value pair collection object

Namespace

Guzzle\Common

Code

public function add($key, $value) {
  if (!array_key_exists($key, $this->data)) {
    $this->data[$key] = $value;
  }
  elseif (is_array($this->data[$key])) {
    $this->data[$key][] = $value;
  }
  else {
    $this->data[$key] = array(
      $this->data[$key],
      $value,
    );
  }
  return $this;
}