3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

preferences:
24.92 ms | 405 KiB | 5 Q