HH\Set::toArray

Returns an array built from the values from this Set, array(val1 => val1, val2 => val2, ...)

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

This maintains set-like semantics in array() land: O(1) membership test with array_has_key($a['key']) and iteration with foreach($a as $member). Int-like strings end up with numerical array keys.

Returns

  • array

Examples

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"
}