Here is a source code showing how to get an array from a given matrix of n rows and m columns.
I publish it here because it prevented me from coding my game directly. I had such a doubt I had to close my project and start experimenting with the loop.
Check the code, you will understand the problem by himself.