what would be a fast and least expensive way to check the values in an array to see if all the values exist.
Lets say that I have an array
$a = array(1,2,3,4,5,6);
I want to match it against arrays
$b = array(6,5,1,3,2,4)
$c = array(1,9,2,3,4,5)
$d = array(6,5,4,3,2,1)
$e = array(1,2,3,4,5,6,7)
$f = array(2,3,4,1,5,6)
.....
etc, etc
In above $a will match $b and $f, since the values are same, though not at same index.
Now I know that I can use foreach/in_array/array_search etc etc and go iterate through each one of the loops and try to get match the values. That could become very expensive very fast, if the array size increases and the amount of arrays we have. I could potentially have 1 million to 2 million + of those arrays and then looping over those in the above mentioned fashion would be a performace nightmare.
My question is what is the best way to achieve this goal. How would you guys go about it? Any ideas would be helpful. thanks
EDIT As I mentioned in my comments below, I am not looking for an answer that was given in the question thought to be duplicate. I want to have O(1) solution and not n^2. The solution there would not help me. I think I will need to have divide this properly or sub bucket the arrays etc. Imagine 1-2 million arrays, now imagine 300 million of those arrays. That solution will not scale.