views:

506

answers:

2

Hi, i was wondering what is the best way to generate an MD5 (or any other hash) of a multi-dimensional array?

I could easily write a loop which would traverse through each level of the array, concatenating each value into a string, and simply performing the MD5 on the string.

However, this seems cumbersome at best and i wondered if there was a funky function which would take a multi-dimensional array, and hash it?

Thanks for your time.

+9  A: 
md5(serialize($array));
Brock Batsell
brilliant!! thanks so much, never knew about this.
Peter John
+1  A: 

Aside from Brock's excellent answer (+1), any decent hashing library allows you to update the hash in increments, so you should be able to update with each string sequentially, instead having to build up one giant string.

See: hash_update

Chris Jester-Young
ok great info, thanks
Peter John