title: Re-format multi dimensional array in PHP
body: <p>I have an array that would like to change the format of data to use for different purpose. Example in below code there are many seasons with link &amp; every season have year. So i would like to index these data under each year.
  My current array:</p>
  
  <pre><code>$infoArray =array( 
                  array(
                      'season'=&gt;'winter 2014', 
                      'link'=&gt;'link1'
                      ),
                  array(
                      'season'=&gt;'summer 2013', 
                      'link'=&gt;'link2'
                      ),
                  array(
                      'season'=&gt;'fall 2012', 
                      'link'=&gt;'link3'
                      ),
                  array(
                      'season'=&gt;'summer 2014', 
                      'link'=&gt;'link4'
                      ),
                  array(
                      'season'=&gt;'winter 2013', 
                      'link'=&gt;'link5'
                      )
              );
  </code></pre>
  
  <p>So now i want make it like below:</p>
  
  <pre><code>$dataArray =array( 
                  '2014'=&gt;array(
                                  'winter'=&gt;'link1', 
                                  'summer'=&gt;'link4'
                                  ),
                  '2013' =&gt;array(
                                  'summer'=&gt;'link2', 
                                  'winter'=&gt;'link5'
                                  ),
                  '2012'=&gt;array(
                                  'fall'=&gt;' link3', 
                                  'link'=&gt;'link3'
                                  ),
                          );                          
  </code></pre>
  
  <p>I was just trying to find some way to solve it with my below code, but so far no luck :(</p>
  
  <pre><code>$newArray =array();
  $innerArray=array();
  
  foreach ($infoArray as $info){
              $season = explode(" ", $info['season']);
              $seasonName = $season[0];
              $seasonYear = $season[1];
  
  
          if (array_key_exists($seasonYear, $newArray)) {
                      $newArray[$seasonYear][$seasonName]=$info['link'] ;
              }
          else {
              $innerArray[$seasonName] = $info['link'];
              $newArray[$seasonYear]=$innerArray ;
          }
  
  }   
  </code></pre>
  
  <p>I hope somebody can point out me where i am getting wrong or if the better solution.</p>
  
  <p>Thanks in advance.</p>