Iterating over multidimensional arrays