foreach ($result as $user) {
$replacements[$user['Email']] = array(
'{FirstName}'=>$user['FirstName'],
'{LastName}'=>$user['LastName'],
'{Code}'=>$user['RandomCode']
);
}
,這就是我想實現的,但是,因爲我需要的變量,而不是固定的輸入,我需要修改它是一個字符串,這裏是代碼:在這種情況下,如何在數組中輸入變量?
try{
$sql =
'SELECT *
FROM require_attributes
where ListID=?
';
$stmt = $conn->prepare($sql);
$stmt->execute(array($list));
$tagSet= $stmt->fetchAll();
}
catch(PDOException $e)
{
die ($e->getMessage().'<a href="mail/campaign_view.php"> Back</a>');
}
try{
$sql =
'SELECT s.*
FROM subscriber s ,list_sub ls
where ls.ListID=?
AND ls.SubID=s.SubID
';
$stmt = $conn->prepare($sql);
$stmt->execute(array($list));
$resultSub= $stmt->fetchAll();
}
catch(PDOException $e)
{
die ($e->getMessage().'<a href="mail/campaign_view.php"> Back</a>');
}
//Put the result in array
foreach ($resultSub as $user) {
$replacements[$user['Email']] = array(
foreach ($tagSet as $tags)
{$string=$string."'".$tags['Attribute']."'"."=>".$user[$tag['Attribute']].",";}
$string = substr($string, 0, -1);
echo $string;
);
第一部分是收集包含{FirstName},{LastName}等的標籤,這些標籤是靈活的,這意味着沒有固定數量的標籤,$ user [$ tag ['Attribute']]是我需要的值去收集。 我如何檢索值並將其放入數組中,就像我想實現的一樣?
目前,它擁有
Parse error: syntax error, unexpected T_ECHO, expecting ')' in C:\xampp\htdocs\fyp\mail\sendPersonal.php on line 186
謝謝你的錯誤。
我不知道你想做什麼(你也許可以張貼輸入/輸出的例子嗎?)。但是你這樣做的方式是非常錯誤的。你不能在數組聲明中做一個foreach循環。這是您的錯誤消息中所說的語法錯誤。 – Tchoupi 2012-03-25 21:18:47