Removes the key/value pair with the specified key from the current Vector


public function removeKey(
  int $k,
): Vector<Tv>;

This will cause elements with higher keys to be assigned a new key that is one less than their previous key. That is, values with keys $k + 1 to n - 1 will be given new keys $k to n - 2, where n is the length of the current Vector before the call to removeKey().

If $k is negative, or $k is greater than the largest key in the current Vector, no changes are made.

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


  • int $k - The key of the key/value pair to remove.

Return Values


Since Vector::removeKey() returns a shallow copy of $v itself, you can chain a bunch of removeKey() calls together.


namespace Hack\UserDocumentation\API\Examples\Vector\RemoveKey;

$v = Vector {'red', 'green', 'blue', 'yellow'};

// Remove 'blue' at index 2

// Remove 'red' and then remove 'green'
object(HH\Vector)#1 (3) {
  string(3) "red"
  string(5) "green"
  string(6) "yellow"
object(HH\Vector)#1 (1) {
  string(6) "yellow"