Skip to content

Commit

Permalink
新增全局函数getHash(),用于在分库或分表场景下获取一个指定长度INT型HASH值
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonweicn committed Jun 26, 2018
1 parent 0cce2e4 commit d9ddf98
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions MiniFramework/Functions/Global.func.php
Expand Up @@ -334,6 +334,7 @@ function isImage($file)

/**
* 获取字符串长度
*
* @param string $string
* @return int
*/
Expand All @@ -344,6 +345,7 @@ function getStringLen($string)

/**
* 让浏览器下载文件
*
* @param string $file 文件路径
* @param string $customName 自定义文件名
* @return output | bool
Expand All @@ -363,6 +365,7 @@ function browserDownload($file, $customName = null)

/**
* 获取文件扩展名
*
* @param string $filename
* @return string
*/
Expand All @@ -372,3 +375,17 @@ function getFileExtName($filename)

return $tmp[count($tmp) - 1];
}

/**
* 获取一个指定长度INT类型HASH值
*
* @param string $s
* @param number $len
* @return number
*/
function getHash($s, $len = 4)
{
$h = sprintf('%u', crc32($s));

return intval(fmod($h, $len));
}

0 comments on commit d9ddf98

Please sign in to comment.