HH\Vector::values

Returns a Vector containing the values of the current Vector

Description

public function values(): Vector<Tv>

Essentially a copy of the current Vector.

This method is interchangeable with toVector().

Return Values

Examples

This example shows how values() is identical to toVector(). It returns a deep copy of $v, so mutating this new Vector doesn't affect the original.

<?hh

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

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

// Make a deep Vector copy of $v
$v2 = $v->values();

// Modify $v2 by adding an element
$v2->add('purple');
var_dump($v2);

// The original Vector $v doesn't include 'purple'
var_dump($v);
Output
object(HH\Vector)#2 (5) {
  [0]=>
  string(3) "red"
  [1]=>
  string(5) "green"
  [2]=>
  string(4) "blue"
  [3]=>
  string(6) "yellow"
  [4]=>
  string(6) "purple"
}
object(HH\Vector)#1 (4) {
  [0]=>
  string(3) "red"
  [1]=>
  string(5) "green"
  [2]=>
  string(4) "blue"
  [3]=>
  string(6) "yellow"
}