I came across a kind of a puzzle today during my coding. I wanted to share and get help from you.
I make a query in to the MySql Database and get results as in an array. So I have an output like this:
$rows=array(n) { // for each n value elements can have different values
["val1"] => string(3) "abc"
["val2"] => string(3) "def"
["val3"] => string(3) "ghi"
["val4"] => string(3) "jkl"
}
So let's say n=4 for instance and i need to create unique pairs that same numbers of pair do not occur in the queue.
What I need is as in the example:
n= 1, 2, 3, 4
Pairs I need to get:
1-2, 1-3, 1-4, 2-3, 2-4, 3-4
I need to avoid the pairs like 2-1. 3-1, 4-1, 3-2, 4-2, 4-3 and 1-1, 2-2, 3-3, 4-4.
For Every Pair, I will Check if this pair of arrays are equal.
How can I do that?
abc-def, abc-ghi, abc-jkl, def-ghi, def-jkl, ghi-jkl..?1-2, 1-3, 1-4, 2-3, 2-4, 3-4