我有以下代码:
foreach($result->response->Results as $entry) {
echo '<tr class="'. $entry->EmailAddress.'">';
echo '<td>'. $entry->EmailAddress.'</td>';
echo '<td></td><td>';
foreach($unsubscribers->response->Results as $entry2) {
echo $entry2->EmailAddress; }
echo '</td><td></td>';
echo '<td></td>';
echo '<td></td>';
echo '</tr>';
}
第一个循环通过广告系列监视器api提取收件人电子邮件地址列表,第二个循环拉入已取消订阅的人。
我的问题是,有100个订阅者被吸引,目前其中一个已取消订阅。那1个取消订阅者通过100次循环,显然会显示出来。
我将如何调整上述内容以使得取消订阅者不会多次显示订阅者。
答案 0 :(得分:2)
你的意思是这样吗?
// Add the unsubscribers to an array
$unsubs = array();
foreach($unsubscribers->response->Results as $entry2) {
$unsubs[] = $entry2->EmailAddress;
}
// Loop through the subscribers
foreach($result->response->Results as $entry) {
echo '<tr class="'. $entry->EmailAddress.'">';
echo '<td>'. $entry->EmailAddress.'</td>';
echo '<td></td><td>';
// If the subscriber is in our unsubscriber array, output the email again
if(in_array($entry->EmailAddress, $unsubs)) {
echo $entry->EmailAddress;
}
echo '</td><td></td>';
echo '<td></td>';
echo '<td></td>';
echo '</tr>';
}
如果该订阅者也在unsubscribers数组中,它只会在第二列输出电子邮件
答案 1 :(得分:1)
检查这些代码,它可能适用于你的方式。
foreach($result->response->Results as $entry){
echo '<tr class="'. $entry->EmailAddress.'">';
echo '<td>'. $entry->EmailAddress.'</td>';
echo '</tr>';
}
foreach($unsubscribers->response->Results as $entry2){
echo '<tr class="'. $entry2->EmailAddress.'">';
echo '<td>'. $entry2->EmailAddress.'</td>';
echo '</tr>';
}