title: PHP MySQLi fetch "array push" overrides data
body: <p>I have 2 arrays:</p>
  
  <pre><code>$arr = [];
  
  $tempArray = [
      'val1' =&gt; "xxx",
      'val2' =&gt; 0,
      'val3' =&gt; 0
  ];
  </code></pre>
  
  <p>Then in my mysql query i fill the temp array with values from the current row and finally push him into the $arr:</p>
  
  <pre><code>$stmt-&gt;bind_result($tempArray["val1"], $tempArray["val2"], $tempArray["val3"]);
  
  while ( $stmt-&gt;fetch () ) {
      array_push($arr, $tempArray);
  }
  </code></pre>
  
  <p>The Problem is, on every loop the "array_push" overrides the data in the <code>$arr</code>. </p>
  
  <p>For example I loop 3 times in the <code>$stmt-&gt;fetch()</code>.</p>
  
  <p><strong>1. Loop</strong></p>
  
  <pre><code>$tempArray = [
      'val1' =&gt; "Hello",
      'val2' =&gt; 1,
      'val3' =&gt; 2
  ]
  
  $arr = [
      0 = [
          'val1' =&gt; "Hello",
          'val2' =&gt; 1,
          'val3' =&gt; 2
      ];
  ]
  </code></pre>
  
  <p><strong>2. Loop</strong></p>
  
  <pre><code>$tempArray = [
      'val1' =&gt; "Stack",
      'val2' =&gt; 3,
      'val3' =&gt; 4
  ]
  
  $arr = [
      0 = [
          'val1' =&gt; "Stack",
          'val2' =&gt; 3,
          'val3' =&gt; 4
      ],
      1 = [
          'val1' =&gt; "Stack",
          'val2' =&gt; 3,
          'val3' =&gt; 4
      ];
  ]
  </code></pre>
  
  <p><strong>3. Loop</strong></p>
  
  <pre><code>$tempArray = [
      'val1' =&gt; "Overflow",
      'val2' =&gt; 5,
      'val3' =&gt; 6
  ]
  
  $arr = [
      0 = [
          'val1' =&gt; "Overflow",
          'val2' =&gt; 5,
          'val3' =&gt; 6
      ],
      1 = [
          'val1' =&gt; "Overflow",
          'val2' =&gt; 5,
          'val3' =&gt; 6
      ],
      2 = [
          'val1' =&gt; "Overflow",
          'val2' =&gt; 5,
          'val3' =&gt; 6
      ]
  ]
  </code></pre>
  
  <p>I never saw this behavior before and i don't know why it does this.</p>
  
  <p><strong>What i want at the end is this:</strong></p>
  
  <pre><code>$arr = [
      0 = [
          'val1' =&gt; "Hello",
          'val2' =&gt; 1,
          'val3' =&gt; 2
      ],
      1 = [
          'val1' =&gt; "Stack",
          'val2' =&gt; 3,
          'val3' =&gt; 4
      ],
      2 = [
          'val1' =&gt; "Overflow",
          'val2' =&gt; 5,
          'val3' =&gt; 6
      ]
  ]
  </code></pre>
  
  <p><strong>$stmt class (requested from @Stevish)</strong></p>
  
  <pre><code>$query = "...";
  if ( $stmt = $this-&gt;db-&gt;prepare($query)) {
          $stmt-&gt;bind_param('i',  $xxx);
          $stmt-&gt;execute();
          $stmt-&gt;store_result();
          $$stmt-&gt;bind_result($tempArray["val1"], $tempArray["val2"], $tempArray["val3"]);
          while ( $stmt-&gt;fetch () ) {
              $arr[] = $tempArr;
          }
      }
  </code></pre>