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;
[text]
MATCHES ODD1 ODD2
Game 1 1.75 2.25
Game 2 1.20 3.50
Game 3 2.50 4.10
[/text]
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;
Code: Select all
$play = array
(
'Game 1' => array(1.75, 2.25),
'Game 2' => array(1.20, 3.50),
'Game 3' => array(2.50, 4.10)
);
Code: Select all
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);
[text]
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
[/text]
MY QUESTIONS ARE
1) Is there anyway i can make it to show as
[text]
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
[/text]
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;
[text]
[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.1
etc
[/text]
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.