public function add($key, $value)
    {
        if ($key === null && is_object($value)) {
            $key = spl_object_hash($value);
        }

        if (!array_key_exists($key, $this->data) && null !== $key) {
            $this->data[$key] = $value;
        } elseif (!array_key_exists($key, $this->data) && null == $key) {
            $this->data[] = $value;
        } elseif (is_array($this->data[$key])) {
            $this->data[$key][] = $value;
        } else {
            $this->data[$key] = [$this->data[$key], $value];
        }

        return $this;
    }
public function add($key, $value)
    {
        if ($key === null && is_object($value)) {
            $key = spl_object_hash($value);
        }

        if (!array_key_exists($key, $this->data) && null !== $key) {
            $this->data[$key] = $value;
        } elseif (!array_key_exists($key, $this->data) && null == $key) {
            $this->data[] = $value;
        } elseif (is_array($this->data[$key])) {
            $this->data[$key][] = $value;
        } else {
            $this->data[$key] = [$this->data[$key], $value];
        }

        return $this;
    }
public function add ( $ key , $ value ) { if ( $ key === null && is_object ( $ value ) ) { $ key = spl_object_hash ( $ value ) ; } if ( ! array_key_exists ( $ key , $ this -> data ) && null !== $ key ) { $ this -> data [ $ key ] = $ value ; } elseif ( ! array_key_exists ( $ key , $ this -> data ) && null == $ key ) { $ this -> data [ ] = $ value ; } elseif ( is_array ( $ this -> data [ $ key ] ) ) { $ this -> data [ $ key ] [ ] = $ value ; } else { $ this -> data [ $ key ] = [ $ this -> data [ $ key ] , $ value ] ; } return $ this ; }
Add a value to a key.

@param string $key   Key to add
@param mixed  $value Value to add to the key

@return GenericCollection Returns a reference to the object.
Add a value to a key .