<?php
$rows = [
(object)["guestEmail" => "you@booking.com"],
(object)["guestEmail" => "you@okay.com"],
(object)["guestEmail" => "me@booking.com"],
(object)["guestEmail" => "n/a"],
(object)["guestEmail" => "somebodyelse@booking.com"],
(object)["guestEmail" => "youAgain@BOOKING.COM"]
];
$blacklist = ['@guest.booking.com', '@booking.com', 'N/A', 'n.c@hotel.com', 'n.c@hotels.com'];
foreach ($rows as $row) {
foreach ($blacklist as $b) {
if (stripos($row->guestEmail, $b) !== false) {
if (isset($blacklistedcounts[$b])) { // this important to avoid Notices
++$blacklistedcounts[$b]; // increment after the element key exists
} else {
$blacklistedcounts[$b] = 1; // set 1 on first occurrence
}
break; // no need to check for other matches for this guestEmail
}
}
}
var_export($blacklistedcounts);