HH\Vector::pop

Remove the last element of the current Vector and return it

public function pop(): Tv;

This function throws an exception if the current Vector is empty.

The current Vector will have n - 1 elements after this operation, where n is the number of elements in the current Vector prior to the call to pop().

Returns

  • Tv - The value of the last element.

Examples

This example shows that pop() returns the last element and removes it from the Vector:

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

$last_color = $v->pop();

\var_dump($last_color);
\var_dump($v);

This example shows that trying to pop from an empty Vector will throw an exception:

$v = Vector {};

$last_element = $v->pop(); // Throws InvalidOperationException