PHP | Ds\Set union() Function Last Updated : 22 Aug, 2019 Comments Improve Suggest changes Like Article Like Report The Ds\Set::union() function is an inbuilt function in PHP which is used to create a new set which contains the union of two sets. Syntax: Ds\Set public Ds\Set::union ( Ds\Set $set ) Parameters: This function accepts a single parameter $set which holds the other set of the instance to combine with the current instance. Return value: It returns a set which contains the union of two sets. Below programs illustrate the Ds\Set::union() function in PHP: Program 1: php <?php // Declare a new set $a = new \Ds\Set([2, 3, 6]); // Declare another new set $b = new \Ds\Set([2, 4, 6, 7]); // Print the Union of both set echo("Union of both set is: \n"); print_r($a->union($b)); ?> Output: Union of both set is: Ds\Set Object ( [0] => 2 [1] => 3 [2] => 6 [3] => 4 [4] => 7 ) Program 2: php <?php // Declare a new set $a = new \Ds\Set([2, 3, 6, 7, 8]); // Declare another new set $b = new \Ds\Set([2, 3, 5, 8, 9, 10]); // Print the union of both set echo("Union of both set is: \n"); var_dump($a->union($b)); ?> Output: Union of both set is: object(Ds\Set)#3 (8) { [0]=> int(2) [1]=> int(3) [2]=> int(6) [3]=> int(7) [4]=> int(8) [5]=> int(5) [6]=> int(9) [7]=> int(10) } Reference: https://www.php.net/manual/en/ds-set.union.php Comment More infoAdvertise with us Next Article PHP | DsMap union() Function R R_Raj Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_set Similar Reads PHP | DsSet union() Function The Ds\Set::union() function is an inbuilt function in PHP which is used to create a new set which contains the union of two sets. Syntax: Ds\Set public Ds\Set::union ( Ds\Set $set ) Parameters: This function accepts a single parameter $set which holds the other set of the instance to combine with t 2 min read PHP | DsMap union() Function The Ds\Map::union() function is an inbuilt function in PHP which is used to create a new map which contains the union of two maps. Syntax: Ds\Map Ds\Map::union( $map ) Parameters: This function accepts single parameter $map which is used to hold the other map of the instance to combine with the curr 2 min read PHP | DsDeque set() Function The Ds\Deque::set() function is an inbuilt function in PHP which is used to set the value at the given index in the Deque. Syntax: public Ds\Deque::set( $index, $value ) : void Parameters: This function accept two parameters as mentioned above and described below: index: This parameter holds the ind 2 min read PHP DsSet sum() Function The Ds\Set::sum() function of Ds\Set class in PHP is an inbuilt function which is used to find the sum of all of the elements present in a Set. Syntax: number public Ds\Set::sum ( void ) Parameter: This function does not accepts any parameter. Return Value: This function returns the sum of the value 1 min read PHP DsMap sum() Function The Ds\Map::sum() function of PHP is used to get the sum of all of the values present in the Map instance. Syntax: number public Ds\Map::sum ( void ) Parameters: This function does not accepts any parameter. Return value: This function returns the sum of all of the values present in the Map instance 1 min read PHP | DsVector set() Function The Ds\Vector::set() function is an inbuilt function in PHP which is used to set the value in the vector at the given index. Syntax: void public Ds\Vector::set( $index, $value ) Parameters: This function accepts two parameters as mentioned above and described below: $index: This parameter holds the 2 min read PHP DsSet sort() Function The Ds\Set::sort() function of DS\Set class in PHP is used to in-place sort the elements of a specified Set instance according to the values. By default, the Set is sorted according to the increasing order of the values. Syntax: void public Ds\Set::sort ([ callable $comparator ] ) Parameters: This f 2 min read PHP | DsSet slice() Function The Ds\Set::slice() function is an inbuilt function in PHP which is used to return the sub-set of given range. Syntax: Ds\Set public Ds\Set::slice ( int $index [, int $length ] ) Parameters: This function accepts two parameters as mentioned above and described below: $index: This parameter holds the 2 min read PHP | DsSequence set() Function The Ds\Sequence::set() function is an inbuilt function in PHP which is used to updates a value at a given index. Syntax: void abstract public Ds\Sequence::set ( int $index , mixed $value ) Parameters: This function accepts two parameters as mentioned above and described below: $index: It is used to 2 min read PHP | DsDeque sum() Function The Ds\Deque::sum() function is an inbuilt function in PHP which is used to return the sum of all elements present in the Deque. Syntax: public Ds\Deque::sum( void ) : number Parameters: This function does not accept any parameter. Return Value: This function returns the sum of all Deque elements. B 2 min read Like