What this code tries to do is find possible combinations of three numbers. For example, let's say I have the following numbers:
1, 2, 3, 4, 5, 6, 7
Some possible combinations of three numbers would be:
1,2,3 1,2,4 2,3,4 2,3,5 2,3,6
I do get the desired outcome but my code looks ugly. Are there any remarks or alternate ways to do this?
<?php
$numbers = [2, 8, 16, 30, 44, 48];
$number = $numbers;
$slice = [];
$threes = [];
$x = 1;
$stake = 10;
$odds = 325;
echo implode(" | ", $numbers)."<br>";
foreach ($numbers as $key) {
if (count($number) == 6) {
// $slice = array_slice($number, 0,3);
$threes[] = $key;
$threes[] .= next($number);
$threes[] .= next($number);
$x++;
array_pop($threes);
$threes[] .= next($number);
$x++;
array_pop($threes);
$threes[] .= next($number);
$x++;
array_pop($threes);
$threes[] .= next($number);
$x++;
//--------------------------------------------------------------//
array_pop($threes);
array_pop($threes);
$threes[] .= prev($number);
array_pop($threes);
$threes[] .= prev($number);
array_pop($threes);
$threes[] .= prev($number);
$threes[] .= next($number);
$x++;
array_pop($threes);
$threes[] .= next($number);
$x++;
array_pop($threes);
$threes[] .= next($number);
$x++;
array_pop($threes);
array_pop($threes);
$threes[] = prev($number);
array_pop($threes);
$threes[] = prev($number);
$threes[] = next($number);
$x++;
array_pop($threes);
$threes[] = next($number);
$x++;
array_pop($threes);
array_pop($threes);
$threes[] = prev($number);
$threes[] = next($number);
$x++;
} elseif (count($number) == 5) {
$threes[] = $key;
$threes[] .= next($number);
$threes[] .= next($number);
$x++;
array_pop($threes);
$threes[] .= next($number);
$x++;
array_pop($threes);
$threes[] .= next($number);
$x++;
array_pop($threes);
array_pop($threes);
$threes[] .= prev($number);
array_pop($threes);
$threes[] .= prev($number);
$threes[] .= next($number);
$x++;
array_pop($threes);
$threes[] .= next($number);
$x++;
array_pop($threes);
array_pop($threes);
$threes[] .= prev($number);
$threes[] .= next($number);
$x++;
} elseif (count($number) == 4) {
$threes[] = $key;
$threes[] .= next($number);
$threes[] .= next($number);
$x++;
array_pop($threes);
$threes[] .= next($number);
$x++;
array_pop($threes);
array_pop($threes);
$threes[] .= prev($number);
$threes[] .= next($number);
$x++;
} elseif (count($number) == 3) {
$threes[] = $key;
$threes[] .= next($number);
$threes[] .= next($number);
}
array_shift($number);
$threes = [];
}
echo "<br>---------------------------------------------------------------------------<br>";
echo "Total combinations of 3's: ".$x."<br>";
?>
$x
as output, or the actual combinations themselves? \$\endgroup\$$x
as output \$\endgroup\$$numbers
array? Why are you storing things in the$threes
and emptying that array after each iteration? \$\endgroup\$