The Ds\Set::diff() function is an inbuilt function in PHP which is used to create a set which contains the elements of the first set which are not present in the second set.
Syntax:
Ds\Set public Ds\Set::diff ( Ds\Set $set )
Parameters: It is used to hold the set, which value need to exclude.
Return Value: It returns a new set containing the elements of the first set which are not present in the second set.
Below programs illustrate the Ds\Set::diff() function in PHP:
Program 1:
<?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 diff of set echo("Difference of set1 and set2: \n"); print_r($a->diff($b)); ?> |
Difference of set1 and set2:
Ds\Set Object
(
[0] => 3
)
Program 2:
<?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 diff of set echo("Difference of set1 and set2: \n"); var_dump($a->diff($b)); ?> |
Difference of set1 and set2:
object(Ds\Set)#3 (2) {
[0]=>
int(6)
[1]=>
int(7)
}
Reference: https://www.php.net/manual/en/ds-set.diff.php
Recommended Posts:
- PHP | Ds\Map diff() Function
- PHP | DateTime diff() Function
- Collect.js | diff() Function
- Moment.js moment().diff() Function
- How to get the function name inside a function in PHP ?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | imagecreatetruecolor() Function
- PHP | fpassthru( ) Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- PHP | Imagick floodFillPaintImage() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() Function
- PHP | cal_to_jd() 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.

