Intro:
I need a function that can take an array and return a hash of it.
This should similar to spl_object_hash(), except that it returns a hash for given array.
So, far I've tried
function array_hash(array $array) {
return spl_object_hash((object) $array);
}
The problems
1) This algorithm isn't efficient by itself. For example, what if I pass something like this:
$array = array(
'foo' => 'bar',
'bool' => false,
'junk' => array(
'junk1' => array('foo' => array('__test__'))
)
)
It won't cast nested arrays to objects.
2) Another major problem is that, spl_object_hash()
returns a different hash for the same object on each new HTTP request.
The question
Again: I need a persistent hash for an array. Unlike spl_object_hash()
, the will be persistent on each HTTP request. How can I do this correctly?