or even better, array_reduce. The early break isn't performance crucial here, right?