title: PHP: get permutations of nested array with recursion
body: <p>I have the nested array structure below.</p>
  
  <pre><code>$letters = array(
      $A = array(1,2),
      $B = array(3,4),
      $C = array(5,6)
  );
  </code></pre>
  
  <p>My goal is to find all possible permutations of the numbers, while the letters must keep the order A-B-C. The expected output is:</p>
  
  <pre><code>1-3-5
  1-3-6
  1-4-5
  1-4-6
  2-3-5
  2-3-6
  2-4-5
  2-4-6
  </code></pre>
  
  <p>Of course, this could easily be accomplished with foreach:</p>
  
  <pre><code>foreach($A as $a){
      foreach($B as $b){
          foreach($C as $c){
              echo $a.$b.$c.'&lt;br&gt;';
          }
      }
  }
  </code></pre>
  
  <p>However, I want this to work dynamically, with a varying number of arrays. I already figured that a recursive approach could work, but I cannot wrap my head around it. Can someone help?</p>