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);
Output for 5.6.38, 7.1.0 - 7.1.22, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
array ( '@booking.com' => 4, 'N/A' => 1, )

preferences:
76.83 ms | 407 KiB | 5 Q