fork download
  1. <?php
  2.  
  3. $d1 = range("A", "C");
  4. $d2 = range("1", "3");
  5. $d3 = range("X", "Y");
  6.  
  7. $in=array($d1, $d2, $d3);
  8.  
  9. $c = new combo($in);
  10. print_r($c->result);
  11.  
  12. class combo{
  13. public $items;
  14. public $result;
  15.  
  16. function __construct( $items){
  17. $this->items= $items;
  18. $result=array();
  19. $this->expand('', 0);
  20. }
  21. function expand( $prefix, $index){
  22. if ($index==count($this->items)){
  23. $this->result[]=$prefix;
  24. return;
  25. }
  26. //empty case
  27. $this->expand($prefix, $index+1);
  28. //combinate
  29. foreach($this->items[$index] as $item){
  30. $this->expand($prefix.$item, $index+1);
  31. }
  32.  
  33. }
  34.  
  35. }
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 
    [1] => X
    [2] => Y
    [3] => 1
    [4] => 1X
    [5] => 1Y
    [6] => 2
    [7] => 2X
    [8] => 2Y
    [9] => 3
    [10] => 3X
    [11] => 3Y
    [12] => A
    [13] => AX
    [14] => AY
    [15] => A1
    [16] => A1X
    [17] => A1Y
    [18] => A2
    [19] => A2X
    [20] => A2Y
    [21] => A3
    [22] => A3X
    [23] => A3Y
    [24] => B
    [25] => BX
    [26] => BY
    [27] => B1
    [28] => B1X
    [29] => B1Y
    [30] => B2
    [31] => B2X
    [32] => B2Y
    [33] => B3
    [34] => B3X
    [35] => B3Y
    [36] => C
    [37] => CX
    [38] => CY
    [39] => C1
    [40] => C1X
    [41] => C1Y
    [42] => C2
    [43] => C2X
    [44] => C2Y
    [45] => C3
    [46] => C3X
    [47] => C3Y
)