所以我想根据比赛的分数进行一些计算。我的代码可以实现我想要的功能,但是感觉不正确,感觉应该有一种更好的方法。
我已经对数组的键中的分数感到怀疑,然后我将所有可能的分数硬编码为10-10,这看起来也不是非常有效和快速。
$score['0-0'] = someFunction($homeExp,0) * someFunction($awayExp,0) / 100; //10%
$score['0-1'] = someFunction($homeExp,0) * someFunction($awayExp,1) / 100; //10%
$score['0-2'] = someFunction($homeExp,0) * someFunction($awayExp,2) / 100; //etc..
$score['0-3'] = someFunction($homeExp,0) * someFunction($awayExp,3) / 100; //etc..
$score['0-4'] = someFunction($homeExp,0) * someFunction($awayExp,4) / 100;
$score['1-0'] = someFunction($homeExp,1) * someFunction($awayExp,0) / 100; //10%
$score['1-1'] = someFunction($homeExp,1) * someFunction($awayExp,1) / 100;
$score['1-2'] = someFunction($homeExp,1) * someFunction($awayExp,2) / 100;
$score['1-3'] = someFunction($homeExp,1) * someFunction($awayExp,3) / 100;
$score['1-4'] = someFunction($homeExp,1) * someFunction($awayExp,4) / 100;
$score['2-0'] = someFunction($homeExp,2) * someFunction($awayExp,0) / 100;
$score['2-1'] = someFunction($homeExp,2) * someFunction($awayExp,1) / 100;
$score['2-2'] = someFunction($homeExp,2) * someFunction($awayExp,2) / 100;
$score['2-3'] = someFunction($homeExp,2) * someFunction($awayExp,3) / 100;
$score['2-4'] = someFunction($homeExp,2) * someFunction($awayExp,4) / 100;
$score['3-0'] = someFunction($homeExp,3) * someFunction($awayExp,0) / 100;
$score['3-1'] = someFunction($homeExp,3) * someFunction($awayExp,1) / 100;
$score['3-2'] = someFunction($homeExp,3) * someFunction($awayExp,2) / 100;
$score['3-3'] = someFunction($homeExp,3) * someFunction($awayExp,3) / 100;
$score['3-4'] = someFunction($homeExp,3) * someFunction($awayExp,4) / 100;
$score['4-0'] = someFunction($homeExp,4) * someFunction($awayExp,0) / 100;
$score['4-1'] = someFunction($homeExp,4) * someFunction($awayExp,1) / 100;
$score['4-2'] = someFunction($homeExp,4) * someFunction($awayExp,2) / 100;
$score['4-3'] = someFunction($homeExp,4) * someFunction($awayExp,3) / 100;
$score['4-4'] = someFunction($homeExp,4) * someFunction($awayExp,4) / 100;
//up till about 10-10
//all scores under 2 goals
$value = $score['0-0'] + $score['0-1'] + $score['1-0']; //30%
//all scores under 3 goals
$value = $score['0-0'] + $score['0-1'] + $score['0-2'] + $score['1-0'] + $score['1-1'] + $score['2-0']; //xx%
//all scores where home wins
$value = $score['1-0'] + $score['2-0'] ... etc etc ;
这是要走的路吗?还是我应该采用其他方法?
答案 0 :(得分:1)
您可以使用两个这样的循环:
for ($i = 0; $i <= 10; $i++) {
for ($j = 0; $j <= 10; $j++) {
$score[$i . '-' . $j] = someFunction($homeExp,$i) * someFunction($awayExp,$j) / 100;
}
}
但是您真正应该问自己的问题是:您是否真的需要计算所有这些并将其放入数组中?并且,如果确实需要,以$ score [4] [3]形式的数组会更好吗?