I'd like to generate a unique identifier based on the content of an array. My initial approach was to simply do:
$key = md5(json_encode($array));
However, I'd like to be absolutely sure that the key is unique and there is a remote possibility that two distinct arrays can produce the same md5 hash. Current idea is to do:
$key = base64_encode(json_encode($array));
This is guaranteed to be unique but produces quite a long key. Can I use sha512 or does this type of hash also have the same potential for key collision as md5? Is there any way to generate a shorter key than the base64 method which is 100% guaranteed to be unique?
To be 100% clear, my question is: How can I generate the shortest possible 100% unique identifier for a set of data?
MD5, but - that's not 100% sure. This is an XY problem, why don't you ask about the real problem you're having? Obviously, you're working with data and you need to ensure you're not receiving duplicates or something similar. I'd leave this perceived solution aside and ask about the real issue which this hashing approach was supposed to solve.