Skip to content

Instantly share code, notes, and snippets.

@polidog
Last active December 16, 2015 14:49
Show Gist options
  • Save polidog/5451209 to your computer and use it in GitHub Desktop.
Save polidog/5451209 to your computer and use it in GitHub Desktop.
<?php
function double_hash($key1, $key2, $salt = null, $callback = "sha1") {
if (!is_numeric($key1) || !is_numeric($key2)) {
return false;
}
$key1 = (int)$key1;
$key2 = (int)$key2;
$first = null;
$second = null;
if ($key1 > $key2) {
$first = $key1;
$second = $key2;
} else {
$first = $key2;
$second = $key1;
}
$str = $first."|".$second.'|'.$salt;
if (is_string($callback) || is_array($callback)) {
return call_user_func($callback, $str);
} elseif (is_object($callback) && $callback instanceof \Closure) {
return $callback($str);
}
return false;
}
var_dump(double_hash(123, 456,"abc"));
var_dump(double_hash(123, 456,"abc"));
var_dump(double_hash(12, 3456,"abc"));
var_dump(double_hash(1234, 56,"abc"));
var_dump(double_hash(1234, 56,"abc",function($str){
return $str;
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment