title: Copy array into another array in PHP
body: <p>I am trying to copy array into another array in PHP. Then send the response as JSON output. But it copies only the last element in array multiple times. Please let me know where I am going wrong? Any help is appreciated</p>
  
  <p><strong>PHP code</strong></p>
  
  <pre><code>stmt_bind_assoc($stmt, $resultrow);
  while ($stmt-&gt;fetch()) {
      $r[] = $resultrow;
      print_r($resultrow);
  }
  echo json_encode($r);
  </code></pre>
  
  <p>Output from <code>print_r($resultrow)</code>.This is correct. Values in array is different</p>
  
  <pre><code>Array( [a_id] =&gt; 1 [b_number] =&gt; 10101010 [dateandtime] =&gt; 2013-12-25 09:30:00 ) 
  Array( [a_id] =&gt; 1 [b_number] =&gt; 20202020 [dateandtime] =&gt; 2013-12-27 11:40:00 )
  </code></pre>
  
  <p><strong>Output from json_encode($r)</strong>.This is incorrect. Values in array is same</p>
  
  <pre><code>[{"a_id":1,"b_number":20202020,"dateandtime":"2013-12-27 11:40:00"},
   {"a_id":1,"b_number":20202020,"dateandtime":"2013-12-27 11:40:00"}]
  </code></pre>