As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago .

What is the best practice in multidimensional array structure in terms of what elements hold the iterator vs the detail elements?

The majority of my programming experience (and I do mainly do it for fun) comes from following tutorials on google, so I apologize in advance if this seems an exceptionally daft question - but I do want to start improving my code.

Whenever I have needed to make a multidimensional array, my naming has always placed the counter in the first element.

For example, if I have a single dimensional array as follows:

$myArray['year']=2012; $myArray['month']='July'; $myArray['measure']=3; // and so on.

However, if I wanted to make that same array keep a few owners of history I would add another dimension and format it as follows:

$myArray[$owner]['year']=2012; $myArray[$owner]['month']='July'; $myArray[$owner]['measure']=3;

Edit: To make sure that my example isn't off-putting or leading in the right direction, I am basically following this structure:

$myArray[rowOfData][columnOfData]

Now, my question is about accepted convention. Should I instead be doing the following?

$myArray['year'][$owner]=2012; $myArray['month'][$owner]='July'; $myArray['measure'][$owner]=3;

Edit: using that edit from above, should it be:

$myArray[columnOfData][rowOfData]

I have searched about array naming conventions, but keep hitting articles arguing about whether to name arrays as plurals or not. The way I have been naming them seems to be more logical and I think it follows a structure that resembles an object better i.e. object->secondaryLevel->detail but for all I know I have been doing it ass-about all this time. As I getting more and more into programming, I would prefer to change my habits if they are wrong.

Is there an accepted standard or is it just anything goes with arrays? If you were looking at code written by someone else, what format would be expecting? I get that any structure that makes sense/is intuitive is accepted.

Also from an iteration point of view, which one of the following is more intuitive?:

for($i=0;$i<$someNumber;$i++) { echo $myArray[$i]['year']; // OR echo $myArray['year'][$owner]; }

Edit: I did have this post tagged as c# and Java because I wanted to get some opinions outside of just PHP programmers. I think that as arrays are used in so many different languages, it would have been good to get some input from programmers in various langauges.