我有一個下面的foreach功能:獲取所有數組值然後將其設置爲的foreach函數在PHP
foreach ($agg as $dep => $emails)
{
$result[] = [
'DEPARTMENTID_FK' => $dep,
'to' => implode(',', $emails),
];
}
echo $to = $result[0]['to'];
$host = 'smtp.office365.com';
$port = '587';
$username = '[email protected];
$password = 'sw0052?';
$headers = array(
'Port' => $port,
'From' => $from,
'To' => $to,
'Subject' => $subject,
'Content-Type' => 'text/html; charset=UTF-8'
);
$recipients = $to.", ".$bcc;
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($recipients, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
現在,我怎麼能得到的所有$to
的價值?
現在我需要手動編輯這個$result[0]['to']
爲$result[1]['to']
看到另一個數據。
我想讓它在循環中。可能嗎?
因此,如果有3個數據,它將在foreach上運行另一個查詢3次。
使用print_r的
Array ([0] => Array ([DEPARTMENTID_FK] => DP0023 [to] => [email protected],[email protected]) [1] => Array ([DEPARTMENTID_FK] => DP0026 [to] => [email protected]))
你可以var轉儲數組,所以我們可以看到它看起來像什麼?我有點困惑爲什麼你嘗試$結果** [0] ** ['到'] – Andreas
嗨@Andreas請參閱我的更新後 –
這是$ agg數組?你想做什麼? – Andreas