经测试代码如下:
/**
* 简单hash算法
*
* @param
* @arrange (512.笔记) jb51.cc
**/
function SimpleHash($str){
$n = 0;
// The magic happens here:
// I just loop trough all letters and add the
// ASCII value to a integer variable.
for ($c=0; $c < strlen($str); $c++)
$n += ord($str[$c]);
// After we went trough all letters
// we have a number that represents the
// content of the string
return $n;
}
//调用方法:
$TestString = 'jb51.cc';
print SimpleHash($TestString);
// returns: 1620
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
原文链接:https://www.f2er.com/php/528923.html