The problem:
Say we need to compare an xml file containing some months to a list of all the months so we can get their corresponding monthNumber (January = 1,  February = 2, …).

First of all we will need a list of months. I decided to go for a multidimensional array with the monthNumber in it aswell:

var monthLabels:Array = new Array([1, "January"],[2, "February"],[3, "March"],
[4, "April"],[5, "May"],[6, "June"],[7, "July"],
[8, "August"],[9, "September"],[10, "October"],
[11, "November"],[12, "December"]);



Then we need another file (which can be strings a user fills in or – in my case – an xml file) to compare data with:

<xml>
<month name = "January">some text</month>
<month name = "Februari">some text 2</month>
<month name = "December">some text 3</month>
</xml>



And here is the code, it’s almost so easy that even flash-for-mobile developers can understand it (for all you mobile developers -> the explanation follows):

for(var i:int = 0; i < xml.month.@name.length(); i++) {
	for(var u:int = 0; u < monthLabels.length; u++) {
		if(xml.month.@name[i] == monthLabels[u][1]) {
			trace(monthLabels[u][0]);
		}
	}
}



The explanation:
First of all we loop through the amount of monthnames (the first for loop). That loop traced out will give us all the monthnames in our file or string (in my xml example 3, being “January”, “February” and “December”).
For each result of that first loop we loop through the monthLabels array’s length. There are 12 months so I could have used “12″ but I use length instead so you can use the code for other data aswell.

In that second loop we check if the value currently being processed by the first loop (xml.month.@name[i]) is equal to one of the values in our array. Since we have a multidimensional array we need to specify which value we want to use to compare with. The month name is on the second place so I use “1″ to identify that place (arrays are zero-based so 0 = first place, 1 = second place). If we have a match the if will succeed and we trace out the corresponding number.

This particular example will trace out:

1  // Which is the monthNumber for January
2 // Which is the monthNumber for February
12 // Which is the monthNumber for December

I hope this helps you multidimensional-and/or-comparing-data troubled kids out!