dqxsuig64994 2014-12-03 15:44 采纳率: 0%
浏览 64
已采纳

编写数学公式的合适方法

I have a formula that works out how to work out a betting accumulator.

The formula is :

Stake x ( Fractional Odds + 1 ) x ( Fractional Odds + 1 ) etc...

I am looking to write a PHP function that loops through the odds and then returns the value.

I have an array as follows (Contains fractional odds)...

$odds = array(
'8/15',
'11/2',
'13/2',
'7/2'
);

Some example PHP code, That shows how I can do this (without a function)...

$result = 10 * (8/15 + 1) * (11/2 + 1) * (13/2 + 1) * (7/2 + 1);
echo number_format($result,2); // 3,363.75

and my stake is set as '10' for now.

What I need to do is loop through the odds array and multiply them by the brackets and to start with multiply by the Stake so for this is test case is 10.

Can anyone suggest a way to write this? When I do try write in * I keep getting PHP errors.

If the topic is not suitable for the community, Please state and I'll remove.

Thanks

  • 写回答

4条回答 默认 最新

  • dongping1922 2014-12-03 15:55
    关注

    Something like this should work

    function compute ($stake, $values) {
        $result = $stake;
    
        foreach ($values as $val)
        {
            $parts = explode('/', $val);
            $result *= ($parts[0] / $parts[1] + 1);
        }
    
        return $result;
    }
    
    
    $stake = 10;
    $odds = array (
        '8/15',
        '11/2',
        '13/2',
        '7/2'
    );
    $result = compute($stake, $odds);
    var_dump($result);
    

    Here's is a working demo you can play with: http://3v4l.org/RNAGH

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?