Jump to content

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;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.