use of foreach loop to display contents from object