Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 11th, 2006, 8:33 PM   #1
MrMan9879
Programmer
 
MrMan9879's Avatar
 
Join Date: Sep 2005
Location: Nanaimo, BC, Canada
Posts: 97
Rep Power: 0 MrMan9879 is an unknown quantity at this point
Send a message via MSN to MrMan9879
Arrays in PHP

Just as a question... how often do you think a PHP programmer will use arrays? I am learning about them right now, and multidimensional arrays seem a bit confusing... There's this line of code in my book that I'm pretty sure explains how to get the content out of three-dimensional arrays with a for loop that I don't really understand how it works... I don't really understand what it means by layer and columns.

[PHP]for ( $layer = 0; $layer < 3; $layer++ )
{
echo "Layer $layer<br />";
for ( $row = 0; $row < 3; $row++ )
{
for ( $column = 0; $column < 3; $column++ )
{
echo '|'.$categories[$layer][$row][$column];
}
echo '|<br />';
}
}[/PHP]

I understand how a for loop works, but I don't really know what it means by $column, $row etc.

Is it just random variable examples that it's using? Or does it actually mean something in the array?

EDIT: Actually, I figured out the code, and how to use the arrays better. If you could answer my first question on how often arrays are used though, that would be nice! :banana:

Last edited by MrMan9879; Jan 11th, 2006 at 8:52 PM.
MrMan9879 is offline   Reply With Quote
Old Jan 12th, 2006, 8:28 AM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
[php]
<?php
$test = array(array(array(1337)));
echo "{$test[0][0][0]} == 1337<br />\r\n";
?>
[/php]

Just a nested array...
__________________

tempest is offline   Reply With Quote
Old Jan 12th, 2006, 8:50 AM   #3
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
Quote:
Originally Posted by MrMan9879
If you could answer my first question on how often arrays are used though, that would be nice! :banana:
They are used more often than in C++ (I think), because you also use them as structs and vectors, and for other things (because entries can have a name, so not only a number you can use them to store information and dump that in e.g. an email).
Polyphemus_ is offline   Reply With Quote
Old Jan 12th, 2006, 8:58 AM   #4
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
Arrays are handy for storing lists of items (ie like a shopping card). I use em on a lot of sites that i have coded over the years.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Jan 12th, 2006, 2:30 PM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
You use them all the freakin' time. I just rewrote a web page to be a lot more interesting: it features arrays inside classes inside arrays.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jan 12th, 2006, 5:10 PM   #6
PhilBon
Hobbyist Programmer
 
PhilBon's Avatar
 
Join Date: Nov 2005
Posts: 172
Rep Power: 3 PhilBon is on a distinguished road
Send a message via AIM to PhilBon Send a message via MSN to PhilBon
I have a calendar, list of poems, list of stories, birthdays, letters, songs, blogs and they are all situated into one page that has an array for each. Anything that is a table is probably in an array of some sort. With Arrays will always come loops. I hope that helps.
PhilBon is offline   Reply With Quote
Old Jan 12th, 2006, 9:18 PM   #7
MrMan9879
Programmer
 
MrMan9879's Avatar
 
Join Date: Sep 2005
Location: Nanaimo, BC, Canada
Posts: 97
Rep Power: 0 MrMan9879 is an unknown quantity at this point
Send a message via MSN to MrMan9879
Thanks guys, I was having a bit of trouble with arrays before, but I think I've got it figured out now... so it isn't a problem if I need to use them all the time.
MrMan9879 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:08 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC