title: Push an associate array into another array
body: <p>I am trying to do a custom WP_query loop and put the results into an array of associate arrays.. It is not working too well.. I realize the array_push overwrites any arrays that have the same indexes so I have the index increment +1 in the loop so they are not identical..however it still is not working.. My results show correct only on the first index (zero).. Here is my code:</p>
  
  <pre><code>&lt;?php 
      $permlink='permalink';
      $excerpt='exerpt';
      $title='title';
      $id='id';    
      $finalarray=array();
  
      for ($i = 0; $i &lt;= 10; $i++) {
          $newitem = array(array(
              'id'.$i =&gt;$id.$i,
              'title'.$i =&gt; $title.$i, 
              'excerpt'.$i =&gt; $excerpt.$i,
              'permalink'.$i =&gt; $permlink.$i 
          ));
          array_push($finalarray, $newitem); 
      }
  
      $count=0;
      foreach($finalarray as $item){
          echo $count.':'.'&lt;br&gt;';
          echo $item[$count]['title'.$count];
          echo $item[$count]['id'.$count];
          echo $item[$count]['permalink'.$count];
          $count++;
      }
  
      var_dump($finalarray);
  ?&gt;
  </code></pre>
  
  <p>Any my results show :</p>
  
  <pre><code>0:
  title0id0permalink01:
  2:
  3:
  4:
  5:
  6:
  7:
  8:
  9:
  10:
  array(11) { [0]=&gt; array(1) { [0]=&gt; array(4) { ["id0"]=&gt; string(3) "id0" ["title0"]=&gt; string(6) "title0" ["excerpt0"]=&gt; string(7) "exerpt0" ["permalink0"]=&gt; string(10) "permalink0" } } [1]=&gt; array(1) { [0]=&gt; array(4) { ["id1"]=&gt; string(3) "id1" ["title1"]=&gt; string(6) "title1" ["excerpt1"]=&gt; string(7) "exerpt1" ["permalink1"]=&gt; string(10) "permalink1" } } [2]=&gt; array(1) { [0]=&gt; array(4) { ["id2"]=&gt; string(3) "id2" ["title2"]=&gt; string(6) "title2" ["excerpt2"]=&gt; string(7) "exerpt2" ["permalink2"]=&gt; string(10) "permalink2" } } [3]=&gt; array(1) { [0]=&gt; array(4) { ["id3"]=&gt; string(3) "id3" ["title3"]=&gt; string(6) "title3" ["excerpt3"]=&gt; string(7) "exerpt3" ["permalink3"]=&gt; string(10) "permalink3" } } [4]=&gt; array(1) { [0]=&gt; array(4) { ["id4"]=&gt; string(3) "id4" ["title4"]=&gt; string(6) "title4" ["excerpt4"]=&gt; string(7) "exerpt4" ["permalink4"]=&gt; string(10) "permalink4" } } [5]=&gt; array(1) { [0]=&gt; array(4) { ["id5"]=&gt; string(3) "id5" ["title5"]=&gt; string(6) "title5" ["excerpt5"]=&gt; string(7) "exerpt5" ["permalink5"]=&gt; string(10) "permalink5" } } [6]=&gt; array(1) { [0]=&gt; array(4) { ["id6"]=&gt; string(3) "id6" ["title6"]=&gt; string(6) "title6" ["excerpt6"]=&gt; string(7) "exerpt6" ["permalink6"]=&gt; string(10) "permalink6" } } [7]=&gt; array(1) { [0]=&gt; array(4) { ["id7"]=&gt; string(3) "id7" ["title7"]=&gt; string(6) "title7" ["excerpt7"]=&gt; string(7) "exerpt7" ["permalink7"]=&gt; string(10) "permalink7" } } [8]=&gt; array(1) { [0]=&gt; array(4) { ["id8"]=&gt; string(3) "id8" ["title8"]=&gt; string(6) "title8" ["excerpt8"]=&gt; string(7) "exerpt8" ["permalink8"]=&gt; string(10) "permalink8" } } [9]=&gt; array(1) { [0]=&gt; array(4) { ["id9"]=&gt; string(3) "id9" ["title9"]=&gt; string(6) "title9" ["excerpt9"]=&gt; string(7) "exerpt9" ["permalink9"]=&gt; string(10) "permalink9" } } [10]=&gt; array(1) { [0]=&gt; array(4) { ["id10"]=&gt; string(4) "id10" ["title10"]=&gt; string(7) "title10" ["excerpt10"]=&gt; string(8) "exerpt10" ["permalink10"]=&gt; string(11) "permalink10" } } }
  </code></pre>
  
  <p>So it looks like the values are in the array, however, only the first index ( zero ) prints correctly.. any suggestions? Also, is there any way i can push an associate array and it not be over written so I dont have to increment the index?</p>