I think that for this kind of treatment an array_reduce is more appropriate.