Arrays are a commonly used feature of many programming languages;
however, multi-dimensional arrays can be confusing at first and once
understood can become a powerful tool to organizing data in your
programs.
Very simply, an array is a list of items: $var = array('Lorem',
'ipsum', 'dolor', 'sit'). Accessing the string 'ipsum' is as simple as
using $var[1] and 'dolor' as $var[2].
A multi-dimensional array is a list of lists: $var =
array(array('Lorem', 'ipsum', 'dolor', 'sit'), array('consectetuer',
'adipiscing', 'elit'), array('Mauris', 'elementum', 'sagittis'));. In
this example, you would access the string 'Lorem' with $var[0][0] and
the string 'adipiscing' with $var[1][2].
Learning multi-dimensional arrays with a bunch of examples looking
like that can be quite confusing since dummy text isn't a real great
real world example. Multi-dimensional arrays can be considered like a
stack of magazines, you can stack as many magazines on top of one
another as you like and each one has its' own space in the stack.
Assuming that we name the stack of magazines $stack, the first
magazine would be $stack[0] the second $stack[1] and so on. Now, every
magazine has pages, from the front cover to the back cover. The cover
of the first magazine would be $stack[0][0], the first page
$stack[0][1] and if you wanted the 17th page of the 207th magazine
$stack[206][17] (remember, array indicies start with 0 so the 207th
magazing is [206] but the cover of the magazine gets the [0] index so
the first mage remains [1]).
If you want to go further into arrays with more dimensions, each page
of a magazine has paragraphs, words and letters. Your
multi-dimensional arrays can become very complex but the idea behind
them is still simple. The 4th letter of the 9th word in the 3rd
paragraph of the 15th page in the 82nd magazine could be referenced
with $stack[81][15][2][7][3] (remembering of course that indicies
start with 0 and that the cover of the magazine gets the 0 index so
page 1 remains [1]). This would return a single letter result, as to
why you might want a single letter from a magazine, I don't know; but,
now you can retrieve it just as easily as the entire word, paragraph,
page, magazine or the entire stack of magazines.
$stack[81] = 82nd magazine
$stack[81][15] = 15th page of the 82nd magazine
$stack[81][15][2] = 3rd paragraph of the 15th page of the 82nd
magazine.
$stack[81][15][2][7] = 8th word of the 3rd paragraph of the 15th page
of the 82nd magazine.
$stack[81][15][2][7][3] = 4th letter of the 8th word of the 3rd
paragraph of the 15th page of the 82nd magazine.
Arrays and Multi-Dimensional Arrays
Support, Snippets & Projects
Moderators: Moderator, Global Moderator
Arrays and Multi-Dimensional Arrays
Love is all a matter of timing.
It's no good meeting the right person too soon or too late.
If I'd live in another time or place...
...my story might have had a very different ending.
It's no good meeting the right person too soon or too late.
If I'd live in another time or place...
...my story might have had a very different ending.
Jump to
- General Category
- ↳ KillaNet Country
- ↳ 2D Graphics
- ↳ KillaNet News
- ↳ 3D & Animation
- ↳ Chatroom
- ↳ Flash
- ↳ Help & Suggestions
- ↳ Game Dev
- ↳ Audio & Video
- ↳ Introductions
- ↳ Journalism
- ↳ Phoenix Lounge
- ↳ Application Dev
- ↳ Toga Toga Toga!!!
- ↳ Photography
- ↳ Main Street Archives
- ↳ Web Design
- ↳ Fonts Icons Cursors & Screensavers
- ↳ Book Reviews
- ↳ General
- ↳ Tech Industry News
- ↳ Legal Resources
- ↳ Industry Contests
- ↳ Graphix Battle Arena
- ↳ KillaNet Contests
- ↳ Competition Archives
- ↳ Education Information
- ↳ Careers
- ↳ Game Studies
- ↳ Motivation
- ↳ Conferences & Seminars
- ↳ KillaDesign
- ↳ Animation & Film
- ↳ The Studio
- ↳ Game Development
- ↳ 2D Graphics
- ↳ Audio & Video
- ↳ 3D Graphics
- ↳ Flash
- ↳ Fonts, Icons & Emoticons
- ↳ Design Requests
- ↳ PhotoShop
- ↳ Cinema 4D
- ↳ Bryce
- ↳ Flash
- ↳ Paint Shop Pro
- ↳ Blender
- ↳ Poser
- ↳ The Darkroom
- ↳ Photo & Camera Discussion
- ↳ Photo Journalism
- ↳ Web Design Principles
- ↳ PHP & MySQL
- ↳ Designing For Print
- ↳ Writer\'s Desk
- ↳ Fiction Writing
- ↳ News Journalism
- ↳ Poetry
- ↳ Technical Writing
- ↳ Biographical Writing
- ↳ General Writing Resources
- ↳ Promotional Writing
- ↳ Film & Television
- ↳ VideoGames
- ↳ Computer Department
- ↳ General Discussion
- ↳ Windows Help
- ↳ Linux Help
- ↳ Builds & Mods
- ↳ Geek Gadgets
- ↳ Security
- ↳ Dev Discussion
- ↳ C++
- ↳ Visual Basic
- ↳ Java
- ↳ Application Skinning
- ↳ IRC Scripting
- ↳ Gaming Centre
- ↳ Guild Wars
- ↳ Aion
- ↳ Computer
- ↳ World of Warcraft
- ↳ Nintendo
- ↳ General RPG & MMORPG
- ↳ PlayStation
- ↳ XBox
- ↳ Other Consoles
- ↳ All Action
- ↳ Racers
- ↳ Sports
- ↳ FPS
- ↳ RTS
- ↳ Sim
- ↳ Casual Games
- ↳ Kids' Games
- ↳ Mobile Games
- ↳ Retro Games
- ↳ Challenges, Friendly Taunts & Discussion
- ↳ Game Requests & Bug Reports
- ↳ Open Source Games
- ↳ Puzzle Games
- ↳ HeadQuarters
- ↳ Uber Coffee Room
- ↳ KillaNet
- ↳ Coffee Room
- ↳ KillaNet
- ↳ KillaGraphix
- ↳ KillaHosting
- ↳ Marketing etc.
- ↳ Staff Issues
- ↳ Reference & Software
- ↳ Archives
- ↳ KillaBlogs
- ↳ Journalism
- ↳ Trash Can
