HH\Vector::removeKey

Removes the specified key from the current Vector.

Description

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

Removes the specified key from the current Vector.

This will cause elements with higher keys to be renumbered by n - 1, where n is the last key in the current Vector.

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

Parameters

  • int $k - The key to remove.

Return Values

Examples

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

<?hh

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

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

// Remove 'blue' at index 2
$v->removeKey(2);
var_dump($v);

// Remove 'red' and then remove 'green'
$v->removeKey(0)->removeKey(0);
var_dump($v);
Output
object(HH\Vector)#1 (3) {
  [0]=>
  string(3) "red"
  [1]=>
  string(5) "green"
  [2]=>
  string(6) "yellow"
}
object(HH\Vector)#1 (1) {
  [0]=>
  string(6) "yellow"
}