The variable `$listeners` of the second foreach can be set by reference too - and then `unset($listeners[$key]);`