RON_ron Posted December 1, 2011 Share Posted December 1, 2011 How to use both $matchInArray[$i] and $matchInArrayR[$i] arrays work within the same loop? my code: $matchInArray = array($match1, $match2, $match3, $match4); $matchInArrayR = array($matchresult1, $matchresult2, $matchresult3, $matchresult4); if($getawayr='Group A'){ $numWins = 0; for($i=0; $i<9; $i++){ if($matchInArray[$i] == "W" && $numWins < 3){ $matchInArrayR[$i] = "Qualified for Semi Finals"; $numWins++; } } } Quote Link to comment https://forums.phpfreaks.com/topic/252189-two-arrays-in-one-loop/ Share on other sites More sharing options...
MasterACE14 Posted December 1, 2011 Share Posted December 1, 2011 Can you forget about your code for a second and tell us what you're trying to achieve? I'm sure there would be a better solution to your problem. Quote Link to comment https://forums.phpfreaks.com/topic/252189-two-arrays-in-one-loop/#findComment-1292948 Share on other sites More sharing options...
RON_ron Posted December 1, 2011 Author Share Posted December 1, 2011 Hi MasterACE14. Thanks for the reply. All what I want now is to action the following; If $match1 = "W" then $matchresult1 should be "Qualified for Semi Finals" If $match2 = "L" then $matchresult2 should be "" If $match3 = "W" then $matchresult3 should be "Qualified for Semi Finals" Condition: Only 2 "Qualified for Semi Finals" are allowed. (ignore if more than 2) $matchInArray = array($match1, $match2, $match3, $match4); $matchInArrayR = array($matchresult1, $matchresult2, $matchresult3, $matchresult4); if($getawayr='Group A'){ $numWins = 0; for($i=0; $i<9; $i++){ if($matchInArray[$i] == "W" && $numWins < 3){ $matchInArrayR[$i] = "Qualified for Semi Finals"; $numWins++; } } } Quote Link to comment https://forums.phpfreaks.com/topic/252189-two-arrays-in-one-loop/#findComment-1292950 Share on other sites More sharing options...
RON_ron Posted December 1, 2011 Author Share Posted December 1, 2011 Does this mean the code is correct? But it's not working. Any idea why? Thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/252189-two-arrays-in-one-loop/#findComment-1292980 Share on other sites More sharing options...
scootstah Posted December 1, 2011 Share Posted December 1, 2011 You could use a multidimensional array. $matches = array(array('match' => $match1, 'result' => $matchresult1), array('match' => $match2, 'result' => $matchresult2), array('match' => $match3, 'result' => $matchresult3), array('match' => $match4, 'result' => $matchresult4) ); if($getawayr='Group A'){ $numWins = 0; for($i=0; $i < count($matches); $i++){ if ($matches[$i]['match'] == 'W' && $numWins < 3) { $matches[$i]['result'] = 'Qualified for Semi Finals'; $numWins++; } } } Quote Link to comment https://forums.phpfreaks.com/topic/252189-two-arrays-in-one-loop/#findComment-1293013 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.