我如何计算列入黑名单的电子邮件的数量并将结果保存到文件中?
例如,我想显示@e-mail.com = 10, N/A = 20
等
$blacklist = ['@email.com', 'N/A', 'n.c@email.com', 'n.c@email.com'];
$date = date('Y-m-d');
foreach ($results->data as $row) {
$emails[] = $row->guestEmail;
foreach ($blacklist as $b) {
if (stripos($row->guestEmail, $b) !== false && date('Y-m-d', strtotime($row->endDate)) == $date) {
$guests[] = array(
'FirstName' => $row->guestFirstName,
'LastName' => $row->guestLastName,
'email' => $row->guestEmail,
'country' => $row->guestCountry,
'check-in_date' => $row->startDate,
'check-out_date' => $row->endDate,
);
}
}
}
答案 0 :(得分:1)
您可以在@上爆炸电子邮件。
然后在$ temp中使用array_keys最大数获取域。
如果始终假定为[1],则找不到“ N / A”。
然后只用计数构建一个数组。
$blacklist = ['@email.com', 'N/A', 'n.c@email.com', 'n.c@email.com'];
Foreach($blacklist as $b){
$temp= explode("@", $b);
$domain = $temp[max(array_keys($temp))];
if (!isset($sum[$domain])) $sum[$domain]= 0;
$sum[$domain]++;
}
var_dump($sum);