title: Multidimensional foreach array returning only the last iteration
body: <p>I'm attempting to format data so that my json code can read it properly.  The end result needs to look like the following:</p>
  
  <pre><code>[2][4][36] = 'Ohio'
  </code></pre>
  
  <p>Where '2' is the region id, '4' is the division id, and '36' is the state id.  Obviously, there are many different results based upon which region and division is selected, but all the results need to be returned as per above.</p>
  
  <p>The result I get from the code below only returns the last iteration.  I'm wondering what I'm doing wrong:</p>
  
  <pre><code>$divisionCodeResults = array();
      foreach($regionCodes as $key =&gt; $value){        
         $divisionCodeResults[$key] = $divisionTable-&gt;getDivisionResultsByRegionCode($key);                
              foreach($divisionCodeResults as $divValue){
                  $array_1 = array();
                  foreach($divValue as $divKey =&gt; $div2Value){                    
                      $array_1[$divKey] = $divKey;   
                      $array_2 = array();
                      foreach($array_1 as $array_1_value){                        
                          $array_2[$key][$divKey] = Doctrine_Core::getTable('state')-&gt;getStatesIdAndNamesThatMatchDivisionKey($array_1_value);
                      }
                  }
             }
      }
  </code></pre>
  
  <p>The above var_dump() outputs the follwing:</p>
  
  <pre><code>array (size=1)
    6 =&gt; 
      array (size=1)
        11 =&gt; 
          array (size=2)
            52 =&gt; string 'Puerto Rico' (length=11)
            54 =&gt; string 'Virgin Islands' (length=14)
  </code></pre>
  
  <p>which is formatted correctly, but as stated, it is only returning the last iteration in a long multidimensional array.</p>
  
  <p>Would appreciate an explanation of what I'm doing wrong... thanks in advance. </p>
  
  <p>EDIT:  </p>
  
  <pre><code>array (size=5)
    2 =&gt; 
      array (size=2)
        4 =&gt; string 'East North Central' (length=18)
        5 =&gt; string 'West North Central' (length=18)
    3 =&gt; 
      array (size=2)
        2 =&gt; string 'New England' (length=11)
        3 =&gt; string 'Mid-Atlantic' (length=12)
    4 =&gt; 
      array (size=3)
        6 =&gt; string 'South Atlantic' (length=14)
        7 =&gt; string 'East South Central' (length=18)
        8 =&gt; string 'West South Central' (length=18)
    5 =&gt; 
      array (size=2)
        9 =&gt; string 'Mountain' (length=8)
        10 =&gt; string 'Pacific' (length=7)
    6 =&gt; 
      array (size=1)
        11 =&gt; string 'Carribean' (length=9)
  </code></pre>
  
  <p>the above is the result of: var_dump($divisionCodeResults); </p>