2015-04-28 63 views
0

我試圖迴應這個Foreach,我不確定正確的方法來做到這一點。我已經嘗試在foreach中創建一個變量並對其進行迴應,但那隻會回顯數組的最後一個值。請讓我看看這樣做的正確方法:意外的T_FOREACH

$client->sendMsgSpecial("Glows Updated", "Your glows have succesfully been updated. The following have been updated: " . 
foreach($glows as $value) { 
echo $value . ', '; 
} 
. "", "glows"); 
+1

你想用最後一行 - >做什麼。 「」,「發光」); –

+0

你得到的錯誤是什麼? –

+0

@tiGer意外的T_FOREACH,如標題所述。 –

回答

1

試着用implode代替產生一個這樣的字符串。

$glowVar = implode(',', $glows); 
$client->sendMsgSpecial("Glows Updated", "Your glows have succesfully been updated. The following have been updated: " . $glowVar . ", "glows"); 

或者,如果想嘗試,然後用自己的方式 -

$str = ''; 
foreach($glows as $value) { 
    $str .= $value . ', '; 
} 
$client->sendMsgSpecial("Glows Updated", "Your glows have succesfully been updated. The following have been updated: " . $str . ", "glows"); 
0

不能呼應的方法調用。使用一個變量。

$message = "Your glows have succesfully been updated. The following have been updated: "; 
foreach($glows as $value) { 
    $message .= $value . ', '; 
} 

然後用變量調用你的方法。

$client->sendMsgSpecial("Glows Updated", $message, "glows"); 

簡短的回答,但希望它有幫助。