Stores a value into the current Vector with the specified key, overwriting the previous value associated with the key

public function set(
  int $key,
  Tv $value,
): Vector<Tv>;

If the key is not present, an exception is thrown. If you want to add a value even if the key is not present, use add().

$vec->set($k,$v) is semantically equivalent to $vec[$k] = $v (except that set() returns the current Vector).

Future changes made to the current Vector ARE reflected in the returned Vector, and vice-versa.


  • int $key
  • Tv $value

Return Values