multidimensional array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Todlerone
Forum Commoner
Posts: 96
Joined: Sun Oct 28, 2007 10:20 pm
Location: Hamilton, Ontario, Canada

multidimensional array

Post by Todlerone »

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
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: multidimensional array

Post by Burrito »

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:

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

Post by Todlerone »

TY for responding Burrito. By the time I had rechecked the forum I got it to work with this..

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;  
        }
    }   
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
Post Reply