Returns the value at the specified key in the current Vector

public function at(
  int $key,
): Tv;

If the key is not present, an exception is thrown. If you don't want an exception to be thrown, use get() instead.

$v = $vec->at($k) is semantically equivalent to $v = $vec[$k].


  • int $key


  • Tv - The value at the specified key; or an exception if the key does not exist.


This example prints the first and last values of the Vector:

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

// Print the first element

// Print the last element

This example throws an OutOfBoundsException because the Vector has no index 10:

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

// Index 10 doesn't exist (this will throw an exception)