@@ -11,7 +11,7 @@ Sets require a min PHP version of 7.1.
11
11
12
12
* [ Installation] ( #installation )
13
13
* [ ** Basic usage:** ] ( #basic-usage )
14
- * [ Creating a Set] ( #creating )
14
+ * [ Creating a Set] ( #creating-a-set )
15
15
* [ Adding values] ( #adding-values )
16
16
* [ Removing values] ( #removing-values )
17
17
* [ Testing if a value is present] ( #testing-if-a-value-is-present )
@@ -20,16 +20,15 @@ Sets require a min PHP version of 7.1.
20
20
* [ As a traditional Array] ( #as-a-traditional-array )
21
21
* [ Using ` entries() ` ] ( #using-entries )
22
22
* [ Using ` each ` ] ( #using-eachcallback-args )
23
- * [ Using ` values ` ] ( #using-values )
24
23
* [ ** Set operations** ] ( #set-operations )
25
24
* [ Union] ( #union )
26
25
* [ Difference] ( #difference )
27
26
* [ Symmetric difference] ( #symmetric-difference )
28
27
* [ Intersect] ( #intersect )
29
28
* [ Subsets] ( #subsets )
30
29
* [ ** Set family operations** ] ( #set-family-operations )
31
- * [ UnionOfArray ] ( #union-of-array )
32
- * [ IntersectionOfArray ] ( #intersection-of-array )
30
+ * [ Family Union ] ( #union-of-a-family-of-sets )
31
+ * [ Family Intersection ] ( #intersection-of-a-family-of-sets )
33
32
34
33
## Installation
35
34
You can download the latest release via the releases link on this page.
@@ -64,9 +63,12 @@ Sets cannot contain duplicate values, and values are stored in insertion order.
64
63
$set = new Set(1, 2, 1, 3, 2);
65
64
````
66
65
67
- If you have an array of elements, you can create a set containing those values .
66
+ If you have an array of elements, you can either pass in the array directly, or splat the array .
68
67
``` php
69
- $set = Set::FromArray([1, 2, 3]);
68
+ $set = new Set([1, 2, 1, 3, 2]);
69
+
70
+ $array = [1, 2, 1, 3, 2];
71
+ $set = new Set(...$array);
70
72
```
71
73
72
74
#### Adding values
@@ -166,6 +168,8 @@ foreach ($set as $val) {
166
168
}
167
169
````
168
170
171
+ Or if you want, you can iterate ` $set->values() ` instead.
172
+
169
173
#### Using ` entries() `
170
174
The ` entries() ` method returns an [ ArrayIterator] ( http://php.net/manual/en/class.arrayiterator.php ) object.
171
175
```` php
@@ -265,33 +269,30 @@ and welcome.
265
269
266
270
#### Union of a Family of Sets
267
271
268
- At present the family of sets needs to be in an array of ` Set ` s.
269
- Then we pass that array of sets to ` Set::UnionOfArray() ` .
270
- For example:
272
+ At present the family of sets needs to be in an array of ` Set ` objects:
271
273
``` php
272
- $set1 = Set(1,2,3);
273
- $set2 = Set(3,4,5);
274
- $set_family = [ $set1, $set2 ];
275
- $set_union = Set::UnionOfArray($set_family);
274
+ $set1 = Set(1, 2, 3);
275
+ $set2 = Set(3, 4, 5);
276
+ $set2 = Set(5, 1, 6);
277
+
278
+ $set_union = Set::familyUnion([$set1, $set2]); // [1, 2, 3, 4, 5, 6]
276
279
```
277
280
278
281
#### Intersection of a Family of Sets
279
282
280
- As with ` UnionOfArray ` , the family of sets needs to be in an array of ` Set ` s.
281
- Then pass that array of sets to ` Set::IntersectionOfArray() ` .
282
- For example:
283
+ As with ` familyUnion ` , the family of sets needs to be in an array of ` Set ` objects:
283
284
``` php
284
285
$set1 = Set(1,2,3);
285
286
$set2 = Set(3,4,5);
286
287
$set_family = [ $set1, $set2 ];
287
- $set_intersection = Set::IntersectionOfArray ($set_family);
288
+ $set_intersection = Set::familyIntersection ($set_family);
288
289
```
289
290
290
291
Note that, contrary to Set Theory, the result of
291
292
taking the intersection of an empty array results
292
293
in an empty array. (In Set Theory the intersection
293
294
of an empty family is undefined as it would be the
294
- 'set of all sets'.)
295
+ [ 'set of all sets'] ( https://en.wikipedia.org/wiki/Universal_set ) .)
295
296
296
297
### Contributing
297
298
Contributions and changes welcome! Just open an issue or submit a PR :muscle :
0 commit comments