PHP | Ds\Set 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 values.
Below programs illustrate the Ds\Set::add() function in PHP:
Program 1:
<?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); ?> |
object(Ds\Set)#1 (4) {
[0]=>
int(1)
[1]=>
string(5) "Geeks"
[2]=>
string(1) "G"
[3]=>
int(10)
}
Program 2:
<?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); ?> |
Ds\Set Object
(
[0] => 10
[1] => 20
[2] => 30
[3] => Geeks
[4] => for
)
Reference: http://php.net/manual/en/ds-set.add.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- How to get the function name inside a function in PHP ?
- p5.js | nf() Function
- p5.js | box() Function
- CSS | rgb() Function
- PHP | min( ) Function
- PHP | max( ) Function
- D3.js | d3.map.set() Function
- PHP Ds\Set get() Function
- D3.js | d3.hsl() Function
- D3.js | d3.min() function
- PHP | dir() Function
- PHP | Ds\Map map() Function
- PHP | end() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



