Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- $a = 1;
- $b = 2;
- $c = 3;
- $types['a'] = array($a,-$a);
- $types['b'] = array($b,-$b);
- $types['c'] = array($c,-$c);
- $combos = combo($types);
- for($i=0;$i<count($combos);$i++){
- echo "Row {$i} => {$combos[$i][0]},{$combos[$i][1]},{$combos[$i][2]}".PHP_EOL;
- }
- function combo($types){
- $t = array_shift($types);
- if(count($types) == 0){
- return $t;
- }
- $c = array();
- $combos = combo($types);
- foreach($t as $z){
- foreach($combos as $combo){
- $combo = is_array($combo) ? $combo : array($combo);
- $c[] = array_merge(array($z),$combo);
- }
- }
- return $c;
- }
- /* OUTPUT:
- Row 0 => 1,2,3
- Row 1 => 1,2,-3
- Row 2 => 1,-2,3
- Row 3 => 1,-2,-3
- Row 4 => -1,2,3
- Row 5 => -1,2,-3
- Row 6 => -1,-2,3
- Row 7 => -1,-2,-3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement