title: How can I create this multidimensional array from a foreach loop?
body: <p>I cannot wrap my head around this...I have an array that looks like:</p>
  
  <pre><code>    Array
  (
      [0] =&gt; Array
          (
              [0] =&gt; 20120412
              [1] =&gt; United States
              [2] =&gt; Illinois
              [3] =&gt; Marion
              [4] =&gt; 2
          )
  
      [1] =&gt; Array
          (
              [0] =&gt; 20120412
              [1] =&gt; United States
              [2] =&gt; Illinois
              [3] =&gt; Carbondale
              [4] =&gt; 2
          )
  
      [2] =&gt; Array
          (
              [0] =&gt; 20120412
              [1] =&gt; United States
              [2] =&gt; Illinois
              [3] =&gt; Carbondale
              [4] =&gt; 2
          )
  )
  </code></pre>
  
  <p>I am wanting it to be like:</p>
  
  <pre><code>array("United States" =&gt; array("Illinois" =&gt; array("Carbondale" =&gt; "4")));
  </code></pre>
  
  <p>So that it takes the Country out, Then the State, then adds together all of the city's numbers.</p>
  
  <p>So far all I have is:</p>
  
  <pre><code>foreach($location_google_data3 as $location_google_data4){
      if($location_google_data4[0]==date("Ymd")){
           $today_visitsbycountry[$location_google_data4[1]]+=$location_google_data4[4];  
      }
  }
  </code></pre>
  
  <p>This gives me an array with the country and number of visits so that I can iterate through it later, but not sure how to proceed with the rest.</p>