title: separate while and foreach and have a common array
body: <p>I would like to have a array in the form:</p>
  
  <pre><code>[1] =&gt; Name1
  
  [2] =&gt; Name2
  
  [1] is my $key1
  
  [2] is my $key2
  </code></pre>
  
  <p>But I've got</p>
  
  <pre><code>[1] =&gt; Name1Name2
  [2] =&gt; Name1Name2
  </code></pre>
  
  <p>Because of my while and my foreach</p>
  
  <p>I do not know how to do it</p>
  
  <p>I have a little framework but you should understand</p>
  
  <pre><code>$uId = gs_post('id');
  
  $array = array();
  
  $Id = '';
  
  foreach ($uId as $key =&gt; $value) {
    $Id .= $key.',';
  }
  
  $Id = substr($Id ,0,-1);
  
  $sql =
    " SELECT ".
    " D.U_ID, CONCAT(U_NAME,' ',U_SURNAME) AS NAME".
    " FROM TABLE1 AS D".
    " JOIN TABLE2 AS A".
    " ON D.U_ID = A.U_ID".
    " WHERE D.U_ID IN (".$Id.")".
    " GROUP BY U_ID";
  
  $res = $this-&gt;query($sql);
  
  while ($row = mysqli_fetch_object($res)) {
  
    foreach ($uId as $key =&gt; $value) {
  
      $array[$key] .= ($row-&gt;NAME);
  
    }
  }
  
    return $array;
  }
  </code></pre>