Created
November 12, 2012 15:37
-
-
Save jasonrhodes/4060025 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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