Replace foreach with in_array