Iterate through multidimensional arrays using for loop