Sokil\Mongo\Operator::pushEachPosition PHP Method

pushEachPosition() public method

The $position modifier specifies the location in the array at which the $push operator insert elements. Without the $position modifier, the $push operator inserts elements to the end of the array. See $push modifiers for more information.
public pushEachPosition ( string $field, integer $position ) : Operator
$field string
$position integer non-negative number that corresponds to the position in the array, based on a zero-based index
return Operator
    public function pushEachPosition($field, $position)
    {
        $position = (int) $position;
        // add modifiers
        if ($position <= 0) {
            throw new Exception('Position must be greater 0');
        }
        if (!isset($this->operators['$push'][$field]['$each'])) {
            throw new Exception('Field ' . $field . ' must be pushed with $each modifier');
        }
        $this->operators['$push'][$field]['$position'] = $position;
        return $this;
    }