2011-06-23 82 views
1

我有這樣的陣列PHP的印刷陣列的幫助

Array ( 
    [3] => Array ( 
    [IDFattura] => 3 
    [Data_Scadenza] => 2011-06-23 
    [Importo] => 343.30 
    [IDTipo_Offerta] => A 
    [Email] => [email protected]) 
    [4] => Array ( 
    [IDFattura] => 4 
    [Data_Scadenza] => 2011-06-23 
    [Importo] => 98.40 
    [IDTipo_Offerta] => A 
    [Email] => [email protected]) 
    [7] => Array ( 
    [IDFattura] => 33 
    [Data_Scadenza] => 2011-06-23 
    [Importo] => 18.40 
    [IDTipo_Offerta] => A 
    [Email] => [email protected])) 

現在我需要發送一個電子郵件給每個電子郵件,但[email protected](在電子郵件正文)將有兩行的表,而不是湯姆那將有1排。 希望你能理解我!

+0

'斯特凡諾@電子郵件。它))''到'[email protected])' – Synxmax

回答

0

你應該重新格式化您的數組是這樣的:

$newArray = array(); 
foreach ($yourArray as $key => $value) { 
    $newArray[$value['Email']][] = $value; 
} 

它返回數組通過電子郵件進行分組。而對於[email protected] tou將擁有一個包含2個項目的數組。

0

循環遍歷數組和組發票通過電子郵件:

$invoicesByEmail = array(); 

foreach($invoices as $invoice) { 
    if(!isset($invoicesByEmail[$invoice['Email']])) { 
    $invoicesByEmail[$invoice['Email']] = array(); 
    } 

    $invoicesByEmail[$invoice['Email']][] = $invoice; 
} 

然後,它是通過分組循環發票和郵寄他們的問題。

foreach($invoicesByEmail as $recipient => $invoices) { 
    $emailBody = ''; 

    foreach($invoices as $invoice) { 
    // Parse your invoice 
    } 

    Mailer::send($recipient, $emailBody, $headers); 
} 
1

試試這個代碼

$newarray = array(); 
foreach($array as $item) $newarray[$item["Email"]] = 1; 
$sendarray = array_keys($newarray); 
foreach($sendarray as $item) mail(...); 

你也應該考慮array_unique

好運

+0

doh。在我加入我之前沒有看到你的。 +1 .. – sdolgy

0

就個人而言,我會結構陣列略有不同。我不會設置數字鍵,而是將密鑰設置爲電子郵件地址。這樣您就可以簡單地使用array_unique

如果不能變化數組作爲你現在,你可以通過它循環,並提取每個電子郵件地址,並把它插入到一個新的數組:

$uniqueEmails = array(); 
foreach ($yourArray as $k => $v) { 
    if (isset($v['Email']) $uniqueEmails[$v['Email']] = $v['Email']; 
} 
return $uniqueEmails;