October 8, 20169 yr Hello Guys,Am developing a matches permutation betting App/Calculator in PHP. The user will have to enter the 2 possible outcomes on each match (win or not win) and combine as many matches as possible. Also will enter amount per bet (eg $10). Then the app will print out possible outcomes of the matches. I have form fields as below; MATCHES ODD1 ODD2Game 1 1.75 2.25Game 2 1.20 3.50Game 3 2.50 4.10 I know this is a multidimensional array. The above give 8 ways of combinations.I want to collect these detail and convert them to a multidimensional array like below; $play = array ( 'Game 1' => array(1.75, 2.25), 'Game 2' => array(1.20, 3.50), 'Game 3' => array(2.50, 4.10) ); I got several php permutation functions like below; function permutations(array $array) { switch (count($array)) { case 1: return $array[0]; break; case 0: throw new InvalidArgumentException('Requires at least one array'); break; } $a = array_shift($array); $b = permutations($array); $return = array(); foreach ($a as $key => $v) { if(is_numeric($v)) { foreach ($b as $key2 => $v2) { $return[] = array_merge(array($v), (array) $v2); } } } return $return; } $combos = permutations($play); echo '<pre>'; print_r($combos); Show result has Array( [0] => Array ( [0] => 1.75 [1] => 1.2 [2] => 2.5 ) [1] => Array ( [0] => 1.75 [1] => 1.2 [2] => 4.1 ) [2] => Array ( [0] => 1.75 [1] => 3.5 [2] => 2.5 )etc MY QUESTIONS ARE1) Is there anyway i can make it to show as Array( [1] => Array ( [Game 1] => 1.75 [Game 2] => 1.2 [Game 3] => 2.5 ) [2] => Array ( [Game 1] => 1.75 [Game 2] => 1.2 [Game 3] => 4.1 ) [3] => Array ( [Game 1] => 1.75 [Game 2] => 3.5 [Game 3] => 2.5 )etc 2) Is it possible to have d multiplication of all the odds multiplied by the amount in an array (1.75 * 1.2 * 2.5 * 10 = 52.5) as below; [1] => Array ( [Game 1] => 1.75 [Game 2] => 1.2 [Game 3] => 2.5 ) $52.5[2] => Array ( [Game 1] => 1.75 [Game 2] => 1.2 [Game 3] => 4.1 ) $86.1etc 3) I want array with the least multiplication be echo out anywhere on the page.Are these possible? If the function above is not the best, it there any better one?Thanks ahead.
October 10, 20169 yr If I understand correctly why not rebuild the array with names? $return = array(); $game1 = 1.75; $game2 = 1.2; $game3 = 2.5; $total = $game1 * $game2 * $game3 * 10; $newrow = array('game1' => $game1, 'game2' => $game2, 'game3' => $game3, 'total' => $total); $return[] = $newrow; Or am I missing something? Edited October 10, 20169 yr by BrowserBugs
Create an account or sign in to comment