title: PHP - foreach repeating values in every new created array
body: <p>I'm looping in an <code>array</code> and trying to get and push each <code>element</code> in another array with <code>associative key</code>. then push it again in another array that serves as a <code>Row</code> array. The loop shouldn't push the previous <code>element</code> on the next <code>Row</code> array. But it keeps repeating till the end of the loop</p>
  
  <p>Output that I am getting.</p>
  
  <pre><code>Array
  (
      [Row1] =&gt; Array
          (
              [Container1] =&gt; Container is empty at row 1
          )
  
      [Row2] =&gt; Array
          (
              [Container1] =&gt; Container is empty at row 1
              [Container2] =&gt; Container is empty at row 2
          )
  
      [Row4] =&gt; Array
          (
              [Container1] =&gt; Container is empty at row 1
              [Container2] =&gt; Container is empty at row 2
              [Container4] =&gt; Container is empty at row 4
          )
  
      [Row5] =&gt; Array
          (
              [Container1] =&gt; Container is empty at row 1
              [Container2] =&gt; Container is empty at row 2
              [Container4] =&gt; Container is empty at row 4
              [Container5] =&gt; Container is empty at row 5
          )
  
      [Row6] =&gt; Array
          (
              [Container1] =&gt; Container is empty at row 1
              [Container2] =&gt; Container is empty at row 2
              [Container4] =&gt; Container is empty at row 4
              [Container5] =&gt; Container is empty at row 5
              [Container6] =&gt; Container is empty at row 6
          )
  </code></pre>
  
  <p>The output that I need to.</p>
  
  <pre><code>Array
      (
          [Row1] =&gt; Array
              (
                  [Container1] =&gt; Container is empty at row 1
              )
  
          [Row2] =&gt; Array
              (
                  [Container2] =&gt; Container is empty at row 2
              )
  
          [Row4] =&gt; Array
              (
                  [Container4] =&gt; Container is empty at row 4
              )
  
          [Row5] =&gt; Array
              (
                  [Container5] =&gt; Container is empty at row 5
              )
  
          [Row6] =&gt; Array
              (
                  [Container6] =&gt; Container is empty at row 6
              )
  </code></pre>
  
  <p>Below is my for loop</p>
  
  <pre><code>&lt;?php
  
  $errorArray = array();
  $ContainerError = array();
  
  for ($i = 1; $i &lt; count($namedDataArray); $i++) { 
      if ($namedDataArray[$i][1] == ''){
          echo '&lt;pre&gt;';
          $ContainerError['Container'.$i] = 'Container is empty at row '. $i;
          echo '&lt;/pre&gt;';
          $errorArray['Row'.$i] = $ContainerError;
      }
  }
  </code></pre>