Collections\Dictionary::add PHP Method

add() public method

public add ( $key, $value )
    public function add($key, $value)
    {
        $storage = $this->storage;
        $storage[$key] = $value;
        return new static($this->keyType, $this->valType, $storage);
    }

Usage Example

コード例 #1
0
 /**
  * {@inheritDoc}
  * @return $this
  */
 public function groupBy($callback)
 {
     $callback = $this->propertyExtractor($callback);
     $group = new Dictionary();
     foreach ($this as $value) {
         $key = $callback($value);
         if (!$group->containsKey($key)) {
             $element = $this instanceof VectorInterface ? new static([$value]) : new ArrayList([$value]);
             $group->add($key, $element);
         } else {
             $value = $group->get($key)->add($value);
             $group->set($key, $value);
         }
     }
     return $group;
 }
All Usage Examples Of Collections\Dictionary::add