HH\Set::toArray

Returns an array containing the values from the current Set.

Description

public function toArray(): array<Tv,Tv>

Returns an array containing the values from the current Set.

For the returned array, each key is the same as its associated value.

Return Values

  • array<Tv,Tv> - an array containing the values from the current Set, where each key of the array are the same as each value.

Examples

<?hh

namespace Hack\UserDocumentation\API\Examples\Set\ToArray;

function run() {
  $s = Set {'red', 'green', 'blue', 'yellow'};

  $array = $s->toArray();

  var_dump(is_array($array));
  var_dump($array);
}

run();
Output
bool(true)
array(4) {
  ["red"]=>
  string(3) "red"
  ["green"]=>
  string(5) "green"
  ["blue"]=>
  string(4) "blue"
  ["yellow"]=>
  string(6) "yellow"
}