To get the count of the blacklisted emails, you'll need to remove the break inside your for loop, like this:
$blacklist = ['@guest.booking.com', '@booking.com', 'N/A', '[email protected]', '[email protected]'];
$blacklistedEmails = false;
$blacklistCount = 0;
foreach ($blacklist as $b) {
if (stripos($row->guestEmail, $b) !== false) {
$blacklistedEmails = true;
$blacklistCount++;
}
}
This will give you the count of the blacklisted emails in $blacklistCount. If you need an array of all the blacklisted items, you could do this:
$blacklist = ['@guest.booking.com', '@booking.com', 'N/A', '[email protected]', '[email protected]'];
$blacklistedEmails = false;
$blackEmails = [];
foreach ($blacklist as $b) {
if (stripos($row->guestEmail, $b) !== false) {
$blacklistedEmails = true;
$blackEmails[] = $row->guestEmail;
}
}
This would give you an array of blacklisted emails in $blackEmails. Then you could just use:
$blacklistCount = count($blackEmails);
That would give you the array and a count.
$i = 0;outside theforeachand then$i++;inside theif.