HH\Set::toSet
Returns a deep copy of the current Set
public function toSet(): Set<Tv>;
Returns
Set<Tv>
- aSet
that is a deep copy of the currentSet
.
Examples
This example shows that toSet
returns a deep copy of the Set
:
$s = Set {'red', 'green', 'blue', 'yellow'};
// Make a deep copy of Set $s
$s2 = $s->toSet();
// Modify $s2 by adding an element
$s2->add('purple');
var_dump($s2);
// The original Set $s doesn't include 'purple'
var_dump($s);
object(HH\Set)#2 (5) {
string(3) "red"
string(5) "green"
string(4) "blue"
string(6) "yellow"
string(6) "purple"
}
object(HH\Set)#1 (4) {
string(3) "red"
string(5) "green"
string(4) "blue"
string(6) "yellow"
}