How can input the variable in an array in this case?
<pre><code>    foreach ($result as $user) {
  $replacements[$user['Email']] = array(
    '{FirstName}'=&gt;$user['FirstName'],
    '{LastName}'=&gt;$user['LastName'],
    '{Code}'=&gt;$user['RandomCode']
  );
}
</code></pre>

<p>That is what i want to achieve , however, since i need variable instead of fixed input , i need to modify it to be a string, here is the code:</p>

<pre><code>try{
$sql =
    'SELECT  *
    FROM     require_attributes
    where ListID=? 
    ';
$stmt = $conn-&gt;prepare($sql);
$stmt-&gt;execute(array($list));
$tagSet= $stmt-&gt;fetchAll();

}
catch(PDOException $e)
    {
    die ($e-&gt;getMessage().'&lt;a href="mail/campaign_view.php"&gt; Back&lt;/a&gt;'); 
    }




try{
$sql =
    'SELECT  s.*
    FROM     subscriber s ,list_sub ls
    where ls.ListID=? 
    AND ls.SubID=s.SubID
    ';
$stmt = $conn-&gt;prepare($sql);
$stmt-&gt;execute(array($list));
$resultSub= $stmt-&gt;fetchAll();
}
catch(PDOException $e)
    {
    die ($e-&gt;getMessage().'&lt;a href="mail/campaign_view.php"&gt; Back&lt;/a&gt;'); 
    }


//Put the result in array
foreach ($resultSub as $user) {
  $replacements[$user['Email']] = array(
  foreach ($tagSet as $tags)
  {$string=$string."'".$tags['Attribute']."'"."=&gt;".$user[$tag['Attribute']].",";}
   $string = substr($string, 0, -1);
  echo $string;
  );
</code></pre>

<p>The first part is to collect the tags which means {FirstName}, {LastName} and so on , The tags are flexible so that means there are not fixed number of tag, 
the $user[$tag['Attribute']] is the value i need to collect. 
How can i retrieve the value and put it into the array just like what i want to achieve?</p>

<p>Currently it has an error of </p>

<pre><code>Parse error: syntax error, unexpected T_ECHO, expecting ')' in C:\xampp\htdocs\fyp\mail\sendPersonal.php on line 186
</code></pre>

<p>Thank you.</p>
