Jump to content

Multidimension array help


Staggan

Recommended Posts

Hello

 

I am after some advice...

 

I have a multidimension array

 


Array
(
   [2] => Array
       (
           [0] => Array
               (
                   [c1] => Bueca Juerniores
                   [s1] => 0
                   [c2] => BUECA JUENIORESITA
                   [s2] => 0
               )

           [1] => Array
               (
                   [c1] => pesfi
                   [s1] => 0
                   [c2] => 
                   [s2] => -1
               )

       )

)

 

This is for some tournament code I am trying to get working... and this is the next set of matches... the 2 in the top array is the round number, and each array below that is a game, game number 0 and game number 1.

 

If any game contains -1 in either s1 or s2 means that game does not yet have all participants... so I would like to discard those arrays... that is the first thing...

 

Then I want to get the round number, game number, c1 and c2 in standard variables... that is step 2

 

But there could be any number of rounds in this array, with any number of games... how can I do it in a loop as well.....

 

Any help would be appreciated

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/273910-multidimension-array-help/
Share on other sites

Example: UN-TESTED

foreach($tournament as $round => $games) {
foreach($games as $game => $teams) {
 if($teams['s1'] == -1 || $teams['s2'] == -1) {
   continue;
 }
echo 'Round: ' . $round . '<br />Game: ' . $game . '<br />Teams: ' . $teams['c1'] . ', ' . $teams['c2'] . '<hr />';
}
}

 

Your array should be in a variable named $tournament;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.