If I have an array with two elements that I want to sha1 hash, what would be the best way to hash irrespective of the order of the elements. This problem also applies for larger arrays and multidimensional arrays.
So [a=1,b=2] and [b=2,a=1] will return the same hash.
node.js has Object-Hash that does exactly this for example.
Sort the array by keys, then serialize it, then hash that.
ksort($array);
$hash = sha1(serialize($array));