title: Concatenate the values from one array to another in PHP
body: <p>I am trying to create a function to generate all the possible combinations of a particular group of characters, and have it variable based on length.</p>
  
  <p>I have a function to create an array of the characters I would like, and this works fine.</p>
  
  <pre><code>function generate_characters($l, $n, $d) {
      $r = array();
  
      if ($l === true) {
          foreach (range('a', 'z') as $index) {
              array_push($r, $index);
          }
      }
  
      if ($n === true) { array_push($r, '0','1','2','3','4','5','6','7','8','9'); }
  
  
      if ($d === true) { array_push($r, '-'); }
  
      return $r;
  }
  </code></pre>
  
  <p>I then need to have it create an array of all possible combinations based on $length, for example if '$length = 1' I need the following array</p>
  
  <pre><code>Array
  (
      [0] =&gt; a
      [1] =&gt; b
      [2] =&gt; c
      [3] =&gt; d
      [4] =&gt; e
      [5] =&gt; f
      [6] =&gt; g
      [7] =&gt; h
      [8] =&gt; i
      [9] =&gt; j
      [10] =&gt; k
      [11] =&gt; l
      [12] =&gt; m
      [13] =&gt; n
      [14] =&gt; o
      [15] =&gt; p
      [.... removed some values to save on length ....]
      [35] =&gt; 9
  )
  </code></pre>
  
  <p>but if '$length = 2' I need this</p>
  
  <pre><code>Array
  (
      [0] =&gt; aa
      [1] =&gt; ab
      [2] =&gt; ac
      [3] =&gt; ad
      [4] =&gt; ae
      [5] =&gt; af
      [6] =&gt; ag
      [7] =&gt; ah
      [8] =&gt; ai
      [9] =&gt; aj
      [.... removed some values to save on length ....]
      [1329] =&gt; 97
      [1330] =&gt; 98
      [1331] =&gt; 99
  )
  </code></pre>
  
  <p>I have tried array_walk() and array_walk_recursive(), along with several foreach and while loops, to no avail.</p>
  
  <p>I can get it to work by manually doing it for each length, but not with a variable length by doing this, but don't know how to make it variable by length.</p>
  
  <pre><code>function generate_two($l, $n, $d) {
      $r = array();
  
      foreach (generate_characters($l, $n, false) as $v1) {
          foreach (generate_characters($l, $n, $d) as $v2) {
              array_push($results, "$v1$v2");
          }
      }
      return $r;
  }
  </code></pre>
  
  <p>all this whilst, not having the '-' as the first character, although I could remove those values after generating the array if I needed to.</p>
  
  <p>Thanks, Dan</p>