foreach solution and test