Jump to content

Multi-Dimensional Arrays


crazyswede

Recommended Posts

I have no trouble with single-dimensional arrays:array[1]= “apples”;array[2]= “oranges”;array[3]= “bananas”; etc.But multi-dimensional arrays baffle me. What do I mean by a multi-dimensional array?array[1a]= “car”; array[1b]= “Ford”; array[1c]= “volkswagon”; array[1d]= “BMW”; etc.array[2a]= “fruit”; array[2b]= “apples”; array[2c]= “oranges”; array[2d]= “bananas”; etc.array[3a]= “toy”; array[3b]= “ball”; array[3c]= “wagon”; array[3d]= “doll”; etc.In the past, working in C, I’d establish it by: ArrayName[][]; though that creates an error in ASP.Please help me.

Link to comment
Share on other sites

To make a multidimensional array, you have to declare each element of an array as a new array:This example is in Javascript:

var a = new Array();a[0] = new Array();a[0][0] = "A1";a[0][1] = "A2";a[1] = new Array();a[1][0] = "B1";a[1][1] = "B2"; alert(a[1][0]); // Displays "B1"

Link to comment
Share on other sites

But multi-dimensional arrays baffle me. What do I mean by a multi-dimensional array?array[1a]= “car”; array[1b]= “Ford”; array[1c]= “volkswagon”; array[1d]= “BMW”; etc.array[2a]= “fruit”; array[2b]= “apples”; array[2c]= “oranges”; array[2d]= “bananas”; etc.array[3a]= “toy”; array[3b]= “ball”; array[3c]= “wagon”; array[3d]= “doll”; etc.
You are attemting to use multi-dimensional, numerical arrays however your indexes contain text. This will error.Multi-dimensional arrays, as shown above work as follows: arrayVariable[arrayIndex][index] For example:Numerical Array:numArray[0][1] = "I am the second index in the numArray[0] array!"; Associative Array:assocArray["bananas"]["color"] = "yellow"; Mixed:mixedArray["name"][6] = "w3schools"; Or you could do the following...array = (insert array here)copyOfArray = array; Hope this helps!
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...