Placed a function call outside a foreach block