Ending the foreach function