Use foreach instead of array_filter.

This allows the loop to be broken on the first non null element.