Added 'f' argument for foreach and associated functions.
Output as array when the flag in f says.