Revert "Collapse foreach into array_map, a bit less readable but still quite understandable"

This reverts commit 99616960ac257d04951aeb7031443a8ca14fdfad.