php - Set Option Value Based on Multiple Variables -
here scoop. making product calculator has 5 different options, value need apply initial variable dependent on 2 separate variables determine right value multiply by.
so logically, have value need multiply variable b, however, value of b dependent on input variables c , d. value b absolute value. add together insult injury, if value less 12, need subtract .5 or .25 depending on value of variable c original value before b applied. lost here.
here original equation excel spreadsheet given me adapt:
=if(and(b9="option_1",b11="horizontal"),d6+k6+1-0.00515464*(d6+k6),if(and(b9="option_1",b11="vertical"),d6+k6+1-0.0064433*(d6+k6),if(and(b9="option_2",b11="horizontal",d6>12),d6+k6-0.5+1-0.010417*(d6+k6),if(and(b9="option_2",b11="vertical",d6>12),d6+k6-0.25+1-0.005208*(d6+k6),if(and(b9="option_2",b11="horizontal",d6<12),d6+k6-0.25+1-0.010417*(d6+k6),if(and(b9="option_2",b11="vertical",d6<12),d6+k6+1-0.005208*(d6+k6),if(and(b9="option_3",b11="vertical",d6>12),d6+k6-0.5+1-0.010417*(d6+k6),if(and(b9="option_3",b11="horizontal",d6>12),d6+k6-0.25+1-0.005208*(d6+k6),if(and(b9="option_3",b11="vertical",d6<12),d6+k6-0.25+1-0.010417*(d6+k6),if(and(b9="option_3",b11="horizontal",d6<12),d6+k6+1-0.005208*(d6+k6),if(and(b9="option_4",b11="vertical"),d6+k6+1-0.03125*(d6+k6),if(and(b9="option_4",b11="horizontal"),d6+k6+1-0.02083*(d6+k6),if(and(b9="option_5",b11="vertical"),d6+k6+1-0.0625*(d6+k6),if(and(b9="option_5",b11="horizontal"),d6+k6+1-0.052083*(d6+k6)))))))))))))))
thanks!
the reply question should provide sort of guidance on how sort of code you've provided (a long string of spreadsheet ternary if
functions quite hard understand) in php more concise, , perhaps more readable.
i don't know if i'm plenty @ explaining sort of thing help you, think of import steps take in process to;
reformat code
putting each status on line of it's own, , each resulting output block on line of it's own, can hugely helpful understanding logic you've got. means can see patterns downwards through code.
group mutual logic
once code formatted nicely, , can perhaps see patterns emerging, should able grouping statements fewer blocks.
having taken these steps myself on code provided, function should provide same output given values of d6
, k6
, b9
, b11
getting in spreadsheet;
function calculatevalue($d6, $k6, $b9, $b11) { $modifiers = array( 'option_1' => array('horizontal' => 0.00515464, 'vertical' => 0.0064433), 'option_2' => array('horizontal' => 0.010417, 'vertical' => 0.005208), 'option_3' => array('horizontal' => 0.005208, 'vertical' => 0.010417), 'option_4' => array('horizontal' => 0.02083, 'vertical' => 0.03125), 'option_5' => array('horizontal' => 0.052083, 'vertical' => 0.0625), ); $x = $d6 + $k6; $y = $modifiers[$b9][$b11]; $sub = 0; if ($b9 == "option_2") { if ($b11 == "horizontal") { $sub += 0.25; } if ($d6 > 12) { $sub += 0.25; } } else if ($b9 == "option_3") { if ($b11 == "vertical") { $sub += 0.25; } if ($d6 > 12) { $sub += 0.25; } } homecoming $x - $sub + 1 - $y * $x; }
hopefully makes logic seem more readable , understandable well.
php logic