Home » Php » Hashing an entire PHP array into a unique value [duplicate]

Hashing an entire PHP array into a unique value [duplicate]

Posted by: admin November 29, 2017 Leave a comment

Questions:

This question already has an answer here:

Answers:

Use md5(serialize()) instead of print_r().

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).

Questions:
Answers:

Alternatively you could use json_encode

Questions:
Answers:

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.

Questions:
Answers:

What about serialize?

$filename = md5(serialize($someArray));

Questions:
Answers:

Using serialize() might be more conservative if you want to keep the type, etc…