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条)

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办