title: PHP how to merge arrays and create keys?
body: <p>I'm working on a custom Single elimination bracket which has to automatically check for results and make a create a round based on results. I can successfully check the results and save the teams in array for the next round but my problem is that it creates a strange array:</p>
  
  <pre><code>    foreach ($competitors as $competitor) {
                      $teams = array();
  
                      if ($competitor['scoreHome'] &gt; $competitor['scoreAway']) {
                          $teams = array(array('home'=&gt;$competitor['home']));
                      } 
  
                      if ($competitor['scoreHome'] &lt; $competitor['scoreAway'] ) {
                          $teams = array(array('away'=&gt;$competitor['away']));
                      }
      }               
                      print_r($teams);
  </code></pre>
  
  <p>OUTPUT:</p>
  
  <pre><code>    Array
      (
          [0] =&gt; Array
          (
              [away] =&gt; testis5
          )
  
      )
      Array
      (
          [0] =&gt; Array
          (
              [home] =&gt; wdefgr
          )
  
      )
      Array
      (
          [0] =&gt; Array
          (
              [away] =&gt; testis4
          )
  
      )
      Array
      (
          [0] =&gt; Array
          (
              [home] =&gt; team1
          )
  
      )
  </code></pre>
  
  <p>What I need is to reindex this array and make <code>array_chunk($teams, 2)</code> so I can then save the information to a database and make this process again until the whole tournament is covered.</p>
  
  <p>Output that I want:</p>
  
  <pre><code>    Array
      (
      [0] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [teamName] =&gt; testis1
                  )
  
              [1] =&gt; Array
                  (
                      [teamName] =&gt; testis5
                  )
  
              )
  
      [1] =&gt; Array
      (
          [0] =&gt; Array
              (
                  [teamName] =&gt; wdefgr
              )
  
          [1] =&gt; Array
              (
                  [teamName] =&gt; testis2
              )
  
      )
  </code></pre>
  
  <p>How can I do that?</p>