The Ds\Set::merge()
function in PHP is used to add all the given values to a set.
The Ds\Set::merge()
function can be declared as shown in the code snippet below:
Ds\Set public Ds\Set::merge ( mixed $values )
mixed $values
: These are the values to be added to the set.The Ds\Set::merge()
function returns the set after adding the given values to it.
The values are not added to the original set. The values are added to a copy of the set and the original set remains unaffected.
Consider the code snippet below, which demonstrates the use of the Ds\Set::merge()
function.
<?php$s1 = new \Ds\Set([1, 2, 3]);var_dump($s1->merge([4, 5]));$s2 = new \Ds\Set(['a', 'b', 'c', 'd']);var_dump($s2->merge(['e']));?>
In line 3, we declare a set s1
.
In line 4, we add the given values to s1
using Ds\Set::merge()
.
In line 6, we declare another set s2
.
In line 7, we add the given values to s2
using Ds\Set::merge()
.