Hello all. Quick question. I'm creating an array to hold a baseball leagues head to head results. How do I create this array so that I get each row to be an array with the teams name with all the columns being the same teams and a default value of "0".
I already have an array that I created from the mysql data. It has id, name format (0, Hitmen, 1 Cougars,etc). I simply want to create an array (table like) with x and y axis the same. Make sense????
Thank-you in advance
multidimensional array
Moderator: General Moderators
Re: multidimensional array
depending on how many dimensions you're talking about creating...you might better off just creating an object.
to answer your question though, you'd do something like this:
to answer your question though, you'd do something like this:
Code: Select all
$myArray = array();
$cnt = 0;
while($row = mysql_fetch_assoc($result))
{
$myArray[$cnt]['team'] = $row['team'];
$myArray[$cnt]['score'] = $row['score'];
//etc
$cnt++;
}
-
Todlerone
- Forum Commoner
- Posts: 96
- Joined: Sun Oct 28, 2007 10:20 pm
- Location: Hamilton, Ontario, Canada
Re: multidimensional array
TY for responding Burrito. By the time I had rechecked the forum I got it to work with this..
TY again...You said this could be created using an object, I have never used objects. That's my next part to learn. Just got to understanding functions and global.
CHEERS
Code: Select all
$Allteams2=$Allteams;
for ($x=0;$x<$num_teams;$x++){
for ($y=0;$y<$num_teams;$y++){
$overall[$Allteams[$x]][$Allteams2[$y]]=0;
}
} CHEERS