This question already has an answer here:
- PHP best way to MD5 multi-dimensional array?
md5(serialize()) instead of
print_r()‘s purpose is primarily as a debugging function and is formatted for plain text display, whereas
serialize() encodes an array or object representation as a compact text string for persistance in database or session storage (or any other persistance mechanism).
Alternatively you could use json_encode
serialize() should work fine.
It has the additional advantage of invoking the
__sleep magic method on objects, and being the cleanest serialization method available in PHP overall.
What about serialize?
$filename = md5(serialize($someArray));
serialize() might be more conservative if you want to keep the type, etc…