PHP | Ds\Set add() Function Last Updated : 22 Aug, 2019 Comments Improve Suggest changes Like Article Like Report The Ds\Set::add() function is an inbuilt function in PHP which is used to add values to the set. Syntax: void public Ds\Set::add( $values ) Parameters: This function accepts a single parameter $values which holds many values to be added in the set. Return value: This function does not return any values. Below programs illustrate the Ds\Set::add() function in PHP: Program 1: php <?php // Declare an empty set $set = new \Ds\Set(); // Use add() function to // add elements to the set $set->add(1); $set->add("Geeks"); $set->add("G"); $set->add(10); var_dump($set); ?> Output: object(Ds\Set)#1 (4) { [0]=> int(1) [1]=> string(5) "Geeks" [2]=> string(1) "G" [3]=> int(10) } Program 2: php <?php // Declare an empty set $set = new \Ds\Set(); // Use add() function to // add elements to the set $set->add(10, 20, 30, "Geeks", "for"); print_r($set); ?> Output: Ds\Set Object ( [0] => 10 [1] => 20 [2] => 30 [3] => Geeks [4] => for ) Reference: http://php.net/manual/en/ds-set.add.php Comment More infoAdvertise with us Next Article PHP | DsDeque set() Function J jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_set Similar Reads PHP | DsSet add() Function The Ds\Set::add() function is an inbuilt function in PHP which is used to add values to the set. Syntax: void public Ds\Set::add( $values ) Parameters: This function accepts a single parameter $values which holds many values to be added in the set. Return value: This function does not return any val 1 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 | 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 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 Like