Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. <?
  2. $a = 1;
  3. $b = 2;
  4. $c = 3;
  5.  
  6. $types['a'] = array($a,-$a);
  7. $types['b'] = array($b,-$b);
  8. $types['c'] = array($c,-$c);
  9.  
  10. $combos = combo($types);
  11.  
  12. for($i=0;$i<count($combos);$i++){  
  13.  echo "Row {$i} => {$combos[$i][0]},{$combos[$i][1]},{$combos[$i][2]}".PHP_EOL;
  14. }
  15.  
  16. function combo($types){
  17.  $t = array_shift($types);
  18.  
  19.  if(count($types) == 0){  
  20.   return $t;
  21.  }  
  22.  $c = array();
  23.  $combos = combo($types);
  24.  foreach($t as $z){  
  25.   foreach($combos as $combo){
  26.    $combo = is_array($combo) ? $combo : array($combo);
  27.    $c[] = array_merge(array($z),$combo);
  28.   }
  29.  }
  30.  return $c;
  31. }
  32.  
  33.  
  34. /* OUTPUT:
  35. Row 0 => 1,2,3
  36. Row 1 => 1,2,-3
  37. Row 2 => 1,-2,3
  38. Row 3 => 1,-2,-3
  39. Row 4 => -1,2,3
  40. Row 5 => -1,2,-3
  41. Row 6 => -1,-2,3
  42. Row 7 => -1,-2,-3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement