add if statement on foreach