Sokil\Mongo\Document::pushEach PHP Method

pushEach() public method

Push each element of argument's array as single element to field value
public pushEach ( string $fieldName, array $values ) : Document
$fieldName string
$values array
return Document
    public function pushEach($fieldName, array $values)
    {
        $oldValue = $this->get($fieldName);
        if ($this->getId()) {
            if (!$oldValue) {
                $this->operator->pushEach($fieldName, $values);
            } elseif (!is_array($oldValue)) {
                $values = array_merge((array) $oldValue, $values);
                $this->operator->set($fieldName, $values);
            } else {
                $this->operator->pushEach($fieldName, $values);
                $values = array_merge($oldValue, $values);
            }
        } else {
            if ($oldValue) {
                $values = array_merge((array) $oldValue, $values);
            }
        }
        // update local data
        parent::set($fieldName, $values);
        return $this;
    }