in reply to compare arrays, and list the difference
If you can afford to spend the memory, then a hash is a great way to find duplicates. Put the keys in the hash (with a dummy value) as you go and use exists() to check for the presence of the key. If the key exists, the value has been seen before. Be careful not to test for truth; zero is a key that exists, but it is false.