Re: how to.. arrays? :D
| From: | Nathan | Date: | Wed, 08 May 2002 21:39:24 +0000 |
| Subject: | Re: how to.. arrays? :D | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-96679@lists.php.net to get a copy of this message | ||
First of all, what is the data to begin with? In your original message you mentioned that you want
team32 = "something" and team22 = "something else" but what is
"something"? Where is this string
coming from?
To give you an idea on how a multi-dimensional array works, it is the same as a normal array, only
each array index's value has its own set of values.
So $array[0][0] is the first array's first value, $array[0][1] is the first array's second
value,
$array[1][4] is the second array's fifth value, etc.
Think of it as looking like your standard Explorer tree (except that I'm not a line artist)....
array
array[0]
array[0][0] = "bob"
array[0][1] = "fred"
array[0][2] = "joe"
array[0][3] = "mama"
array[1]
array[1][0] = "sven"
array[1][1] = "jorgie"
array[1][2] = "olie"
array[2]
array[2][0] = "helga"
array[2][1] = "hanz"
array[2][2] = "franz"
Does that make sense?
Anyway, to do this in a loop, you would need to nest them like so:
$team = array(); // initialize it
for ($g = 1; $g <= 4; $g++) {
for ($r = 1; $r <= 4; $r++) {
$team[$g][$r] = $your_string_array;
}
}
What this will do is on the first pass, set group 1's array for each rank, then on the next
pass,
set group 2's array for each rank, etc.
Then you can get any team info you want by echoing like so:
echo $team[2][3]; // this spits out group 2's rank.
You see? Need more info?
# Nathan