title: PHP: Adding an element in array in foreach loop
body: <p>I want to add a new index to an array and add values to it in a loop. </p>
  
  <p>for example i've following array in a loop </p>
  
  <pre><code>[books] =&gt; Array
          (
              [0] =&gt; stdClass Object
                  (
                      [id] =&gt; 1
                      [user_id] =&gt; 5
                      [book_id] =&gt; 1
                      [date_issue] =&gt; 2016-07-24 00:00:00
                      [date_return] =&gt; 2016-07-25 00:00:00
                  )
  
              [1] =&gt; stdClass Object
                  (
                      [id] =&gt; 5
                      [user_id] =&gt; 5
                      [book_id] =&gt; 2
                      [date_issue] =&gt; 2016-07-24 00:00:00
                      [date_return] =&gt; 2016-07-25 00:00:00
                  )
  
          )
  </code></pre>
  
  <p>This is how i am getting it      </p>
  
  <pre><code>  foreach ($query_books-&gt;result() as $key =&gt; $value) {
       $result['books']= $query_books-&gt;result();
   }
   print_r($result); 
  </code></pre>
  
  <p>now in each iteration i want  to add a new index after <code>[date_return]</code> how do  i do that please help </p>