Php打印阵列的帮助

时间:2011-06-23 07:35:50

标签: php arrays printing

我有这个数组

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

现在我需要向每封电子邮件发送一封电子邮件,但是stefano@email.it(在电子邮件正文中)将有一个包含两行的表,而不是Tom将有一行。 希望你理解我!

4 个答案:

答案 0 :(得分:1)

试试这段代码

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

您还应该考虑array_unique

祝你好运

答案 1 :(得分:0)

您应该像这样重新格式化数组:

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

返回按电子邮件分组的数组。对于stefano@email.it,tou将有一个包含2个项目的数组。

答案 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);
}

答案 3 :(得分:0)

就个人而言,我的阵列结构略有不同。我没有使用数字键,而是将密钥设置为电子邮件地址。这样您就可以使用array_unique

如果您无法更改现在的数组,您可以遍历它并提取每个电子邮件地址并将其插入新数组中:

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