Full and Partial Matching of Sets
Posted
by
jeffrey
on Stack Overflow
See other posts from Stack Overflow
or by jeffrey
Published on 2011-03-15T07:51:25Z
Indexed on
2011/03/15
8:10 UTC
Read the original article
Hit count: 179
I have several sets of the same type [Y, M, D] and am trying to write a function to search these sets and return an array of the available sets that fit my parameters.
ReturnedSets = return_matches(Y,M,D);
I want the three parameters of the function return_matches to be optional. Which means any combination of values can be used to return the sets.
For example, one could write - return_matches(13,null,2); - and the function would look for all sets that contain [13, anyValue, 2];
I'm writing this in PHP, to allow users to manage dated files on my website, but I'd like to be able to use this function again for other uses.
Thanks!
edit: (This, or variations of this, is all I can come up with so far... There is something extra that I don't understand, because this function ends up / would not work to return sets that contain y and d, but leaving m arbitrary.
if(y == s[0]){
if(m == s[1]){
if(d == s[2]){
print "day match";
}
} else {print "month match";}
} else {print "year match";}
} else {print "no match";}
© Stack Overflow or respective owner