Staggan Posted February 1, 2013 Share Posted February 1, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/273910-multidimension-array-help/ Share on other sites More sharing options...
jcbones Posted February 1, 2013 Share Posted February 1, 2013 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; Quote Link to comment https://forums.phpfreaks.com/topic/273910-multidimension-array-help/#findComment-1409538 Share on other sites More sharing options...
Staggan Posted February 1, 2013 Author Share Posted February 1, 2013 Thanks That allowed me to complete the code... Much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/273910-multidimension-array-help/#findComment-1409580 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.