【发布时间】:2016-06-09 14:12:25
【问题描述】:
我的代码是:
$itemArray = array();
foreach ($a->getDetails() as $b) {
if ($b->getValue1() !== $b->getValue2()) {
if (!array_key_exists($b->getId(), $itemArray)) {
$itemArray[$b->getId()] = array('name' => $b->getName(), 'age' => $b->getAge());
}
}
}
if (count($itemArray) > 0 && $b->getValue1() !== $b->getValue2()) {
foreach($itemArray as $item) {
$personName = $item['name'];
$personAge = $item['age'] ;
$content = ('Name is: ' . $personName . ', age is: ' . $personAge);
}
}
$emailAddress = 'emailaddress@gmail.com';
$fromEmail = 'noreply@gmail.com';
$body = <<<EOF
Here is an example email:
$content
EOF;
$mail = new sfMail();
$mail->setBody($body);
$mail->send();
现在邮件只输出一个条目,例如:
Name is: Bob, age is: 20.
但我希望电子邮件在$b->getValue1() !== $b->getValue2() 喜欢时输出数组的所有条目:
Name is: Bob, age is 20:
Name is: John, age is 30.
如何设置我的内容变量,以便它从数组中获取所有内容并在电子邮件中很好地输出?
谢谢!
【问题讨论】:
-
追加 .您的 。内容 。到 。你的变量。和 。别 。覆盖。它。
标签: php arrays loops email associative-array