Hi, Can anyone recommend a faster way to find matches of values held in 2 arrays? I have something that works but it's really slow.

I have 2 2D arrays. Array1[X][Y] and Array2[X][Y]. For each value in Array1[X][0] ( ie the first column ) I want to see if there is a matching value in Array2[X][0]. If there is then I want to populate a 3rd array. The length of the arrays can vary but both are in the order of 100k rows.

You do not need the for $j loop at all. If there is a match, you create an Array3 entry with $j set to zero and exit the $j loop. If there is not a match, you repeat the test about 100k times , always getting the same result. Good Luck, Bill

Wow thank you so much. That has dropped my matching time from 31 minutes to 26 seconds. I'll need to read up more on hashes to understand why there is such a difference, as I always thought of a hash as just the keyvalue, basically. So much to learn.

You could thing of a hash as a special type of array where the indexes are words (strings of characters) rather than numbers. Technically, it is something somewhat more complicated thanthat, but from a user standpoint that's basically what it boils down to.

In this case the fact that you can access directly to the value using the key means that you no longer need the two nested loops that you used, but just one loop. Assuming you have two arrays with 1,000 entries each, the nested loops approach leads to up to 1,000,000 queries (for each elements in array A, look all elements of array B to find a match), wheras the hash approach leads basically to 2,000 queries. This is bound to be much faster. And the more data you have, the larger the advantage of the hash approach will be.