This is WAY overkill, and the suggestion of returning left-most digit is the best...
function myfunc($md5) {
$total = 0;
foreach (str_split($md5) as $char) $total += ord($char);
return $total % 9 + 1;
}
echo myfunc("098f6bcd4621d373cade4e832627b4f6");
This way you can easily change the range of return values you are interested in by modifying the return statment.
Or, a more compact version:
function myfunc2($md5) {
return array_sum(array_map("ord", str_split($md5))) % 9 + 1;
}
You could even pass the min and max as args:
function myfunc2($md5, $min = 1, $max = 9) {
return array_sum(array_map("ord", str_split($md5))) % $max + $min;
}
myfunc2("098f6bcd4621d373cade4e832627b4f6", 10, 20);