Skip to content

Instantly share code, notes, and snippets.

@jasonrhodes
Created November 12, 2012 15:37
Show Gist options
  • Save jasonrhodes/4060025 to your computer and use it in GitHub Desktop.
Save jasonrhodes/4060025 to your computer and use it in GitHub Desktop.
<?php
$params = array(
"type" => "json",
"v" => 1,
"api_key" => "4539653423sa35",
"topic" => "science",
"edition" => "fall"
);
# List of keys to ignore
$ignore = array("type", "api_key");
# We have to abstract a keysorter function because
# ksort() sorts by reference, making it unchainable
function keysort($array) {
ksort($array);
return $array;
}
# This will show you what the hasher/key maker will do before it serializes/hashes
print_r(keysort(array_diff_key($params, array_fill_keys($ignore, null))));
# This is the hashed key, ready for apc_store(), apc_fetch(), apc_exists(), etc
echo md5(serialize(keysort(array_diff_key($params, array_fill_keys($ignore, null)))));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment