Added foreach loop for  Array
Moved echo statement within loop and removed repeated statements