IT Community - Software Programming, Web Development and Technical Support

Three dimensional array

This is a discussion on Three dimensional array within the Flash Actionscript Programming forums, part of the Web Development category; Could anyone please explain about the three dimensional array? If you give any example it will be great!!!...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Flash Actionscript Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 09-20-2007, 07:46 AM
geoblow geoblow is offline
D-Web Trainee
 
Join Date: Jul 2007
Posts: 19
geoblow is on a distinguished road
Wink Three dimensional array

Could anyone please explain about the three dimensional array?
If you give any example it will be great!!!
__________________
Geo
Actionscript Villain
geoblow.com
Atleast an inch move every day!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-21-2007, 04:47 AM
aramesh aramesh is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 72
aramesh is on a distinguished road
Default Re: Three dimensional array

Hi,
Multidimensional arrays can be thought of as matrices, or grids. A chess board is a grid of 8 columns and rows. In programming, multidimensional arrays can be used to model these types of structures. The following array, twoD_Array, consists of two array elements that are themselves arrays consisting of two elements:

twoD_Array = new Array(new Array("one","two"), new Array("three", "four"));

In this case, twoD_Array is the "main" array containing two nested arrays.

Nested for loops can be used to quickly create multidimensional arrays. For example, the following script creates a 5 x 5 array and sets the value of each array node to its index:

mainArray = new Array(5);
for(i=0; i<5; i++) {
mainArray[i] = new Array(5);
for(j=0; j<5; j++) {
mainArray[i][j] = "[" + i + "][" + j + "]";
}
}

Retrieving array elements

To retrieve elements of a multidimensional array, you use multiple array access operators [] after the name of the top-level array. The first [] refers to the index of the top level array. Subsequent []'s refer to elements of nested arrays. Using twoD_Array as an example:

twoD_Array[0][0]
twoD_Array[1][1]

Nested for loops can be used to iterate through the elements of a multidimensional array. In the following example, the outer loop loops through each element of mainArray. The inner loop iterates through each nested array and outputs each array node. The length property of each array is used as the loop condition:

outerArraylength = mainArray.length;
for(i=0; i < outerArraylength; i++) {
innerArrayLength = mainArray[i].length;
for(j=0; j < innerArraylength; j++){
trace(mainArray[i][j]);
}
}


<aramesh>
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What’s the difference between the System.Array.CopyTo() and System.Array.Clone() ? Archer C# Programming 2 08-25-2007 03:00 AM
When to you use $_REQUEST[ ] array in php..? oxygen PHP Programming 2 07-30-2007 04:52 AM
How you print the array using Perl? raj Perl 1 07-25-2007 01:02 AM
Array filtering Jeyaseelansarc PHP Programming 1 07-17-2007 09:07 AM
Paging array in PHP kingmaker PHP Programming 0 07-16-2007 11:11 PM


All times are GMT -7. The time now is 07:48 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0