我有以下代码:
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>';
}
第一个循环通过campaign monitor api拉入收件人电子邮件地址列表,第二个循环拉入取消订阅的人。
我的问题是,有100个订阅者被拉进来,目前其中1个已经取消订阅。这1个取消订阅的人被循环了100次,显然会被显示出来。
我该如何调整以上内容,使其在有多少次订阅者的情况下都不会显示取消订阅。
你的意思是这样的吗?
// 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>';
}
如果订阅者也在取消订阅数组
检查这些代码,它可能适合您的方式。
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>';
}