将数字范围映射到0到100

Geo*_*tiz 1 php algorithm math

我有可能在+/- 6之间包括0(即6,5,4,3,2,1,0,-1,-2,-3,-4,-5,-6)超出我在PHP中的排名算法.

而不是返回+/- 6,我想返回0到100之间的数字.相关性类似于:

100 = +6
..
75 = +3
..
50 = 0
..
25 = -3
..
0 = -6

考虑到排名算法的输出范围,我将如何在PHP中以编程方式实现此目的?我考虑过以下内容但不确定最佳方法:

function score_alg($x) {
  if ($x == '6')
    return 100;
  if ($x == '3')
    return 75;
  if ($x == '0')
    return 50;
  if ($x == '-3')
    return 25;
  if ($x == '-6')
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Tim*_*ers 5

这可行:

function score_alg($x) {
  return round(($x+6)*(100/12));
}
Run Code Online (Sandbox Code Playgroud)