Here's two functions I made out of boredom from something I learned in about in math today.
PHP Code:
public function setUnion(set1, set2) {
temp.set = set1;
for (i=0; i<set2.size(); i++) {
if (!set2[i] in set1)
temp.set.add(set2[i]);
}
temp.set.sortascending();
return temp.set;
}
public function setIntersection(set1, set2) {
temp.set = NULL;
for (i=0; i<set2.size(); i++) {
if (set2[i] in set1)
temp.set.add(set2[i]);
}
temp.set.sortascending();
return temp.set;
}
If you didn't know, sets are pretty much arrays. setUnion(set1, set2) essentially combines two arrays, and setIntersection(set1, set2) makes an array of values that are in both sets (arrays).