title: PHP output all possible number combinations
body: <p>Ok, I've almost finished my script, but my output is not quite as supposed to be. Scripts task is to create all possible number combinations from the sum of all multidimensional array keys. Ive edited few scripts and combined in one script, but I cant seem to get desired output.</p>
  
  <p>Ok, for example, lets say I have array like this one:</p>
  
  <pre><code>$test = array(0 =&gt; array(53, 22, 12),
      1 =&gt; array(94, 84, 94),
      2 =&gt; array(56, 45, 104)
  );
  </code></pre>
  
  <p>Then I fetch array keys and store them in new array:</p>
  
  <pre><code>foreach ($test as $key =&gt; $row) {
      $output[] = count($row);          
  }                                       
  for($keycount = 1; $keycount &lt;= count($output); $keycount++){
      $newarray[$keycount] = $keycount;
  }
  </code></pre>
  
  <p>And then I count keys from newly created array, so the final combination is based on that number. In aforementioned example, I have 3 combinations, so the final array is supposed to look like this:</p>
  
  <pre><code>111
  211
  311
  121
  221
  321
  131
  231
  331
  112
  .
  .
  .
  333
  </code></pre>
  
  <p>But with my script:</p>
  
  <pre><code>$arraycount = count($newarray);
  $maxcombinations = pow($arraycount, $arraycount);
  $return = array();
  $conversion = array();
  foreach ($newarray as $key =&gt; $value) {
      $conversion[] = $key;
  }
  for ($i = 0; $i &lt; $maxcombinations; $i++) {
      $combination = base_convert($i, 10, $arraycount);
      $combination = str_pad($combination, $arraycount, "0", STR_PAD_BOTH);
      $return[$i][] = substr(strtr($combination, $conversion), 1, $arraycount);
  }     
  echo "&lt;pre&gt;".print_r($return, true)."&lt;/pre&gt;";
  </code></pre>
  
  <p>I'm getting output like this:</p>
  
  <pre><code>Array
  (
  [0] =&gt; Array
      (
          [0] =&gt; 111
      )
  
  [1] =&gt; Array
      (
          [0] =&gt; 121
      )
  
  [2] =&gt; Array
      (
          [0] =&gt; 131
      )
  
  [3] =&gt; Array
      (
          [0] =&gt; 211
      )
  
  [4] =&gt; Array
      (
          [0] =&gt; 221
      )
  
  [5] =&gt; Array
      (
          [0] =&gt; 231
      )
  
  [6] =&gt; Array
      (
          [0] =&gt; 311
      )
  </code></pre>