RON_ron Posted December 1, 2011 Share Posted December 1, 2011 I'm not sure what am I doing wrong? I want to check if match1, match2 or match 3 has "W" and the continues count ($numOfWinsCount) to be maximum of 2. If $numOfWinsCount is more than 2 do not continue with $matchresult . $matchWcounter = "Qualified for Quarter Finals!"; My Code: $match1 = "W" $match2 = "W" $match3 = "L" $getawayr="Group A"; if($getawayr=="Group A"){ for ( $matchWcounter = 1; $matchWcounter <= 3; $matchWcounter ++) { $numOfWinsCount = 0; if($match . $matchWcounter=="W" and $numOfWinsCount <3){ $numOfWinsCount=$numOfWinsCount+1; $matchresult . $matchWcounter = "Qualified for Quarter Finals!"; } } } Quote Link to comment https://forums.phpfreaks.com/topic/252184-apply-condition-to-the-output-based-on-the-count-value/ Share on other sites More sharing options...
MasterACE14 Posted December 1, 2011 Share Posted December 1, 2011 you need to use either an array or this... ${'match'.$matchWcounter} $match . $matchWcounter is appending their values, rather than the variable names. Personally I think an array is more appropriate. $match = array(); $match[1] = "W" $match[2] = "W" $match[3] = "L" $getawayr="Group A"; if($getawayr=="Group A"){ for ( $matchWcounter = 1; $matchWcounter <= 3; $matchWcounter ++) { $numOfWinsCount = 0; if($match[$matchWcounter]=="W" and $numOfWinsCount <3){ $numOfWinsCount=$numOfWinsCount+1; $matchresult . $matchWcounter = "Qualified for Quarter Finals!"; } } } Quote Link to comment https://forums.phpfreaks.com/topic/252184-apply-condition-to-the-output-based-on-the-count-value/#findComment-1292916 Share on other sites More sharing options...
marcus Posted December 1, 2011 Share Posted December 1, 2011 $match = array('W','W','L'); $getAwayR = "Group A"; if($getAwayR == "Group A"){ $numWins = 0; for($i = 0; $i < count($match); i ++){ if($match[$i] == "W" && $numWins < 3){ // whatever else $numWins++; } } } Quote Link to comment https://forums.phpfreaks.com/topic/252184-apply-condition-to-the-output-based-on-the-count-value/#findComment-1292917 Share on other sites More sharing options...
scootstah Posted December 1, 2011 Share Posted December 1, 2011 First off, $numOfWingsCount will never be greater than 2 because you set it to 0 every iteration. You need to assign it to 0 before the for loop. If you were using an array this would be easier. You could do: $match = array('W', 'W', 'L'); // inside for loop if ($match[$matchWcounter] == 'W' Otherwise you have to do something like this: // inside for loop if (${'match' . $matchWcounter} == 'W' I can't test this right now so, try it and see if it works. Quote Link to comment https://forums.phpfreaks.com/topic/252184-apply-condition-to-the-output-based-on-the-count-value/#findComment-1292918 Share on other sites More sharing options...
MasterACE14 Posted December 1, 2011 Share Posted December 1, 2011 $match = array('W','W','L'); $getAwayR = "Group A"; if($getAwayR == "Group A"){ $numWins = 0; for($i = 0; $i < count($match); i ++){ if($match[$i] == "W" && $numWins < 3){ // whatever else $numWins++; } } } this is a much cleaner solution RON_ron, I'd just change one thing. $count = count($match); for($i = 0; $i < $count; i ++){ Quote Link to comment https://forums.phpfreaks.com/topic/252184-apply-condition-to-the-output-based-on-the-count-value/#findComment-1292919 Share on other sites More sharing options...
RON_ron Posted December 1, 2011 Author Share Posted December 1, 2011 wow! thanks guys! but something is wrong. It says syntax error, unexpected T_INC, expecting ')' $getAwayR = "Group A"; $matchInArray = array($match1, $match2, $match3, $match4, $match5, $match6, $match7, $match8, $match9); $matchInArrayResu = array($matchresult1, $matchresult2, $matchresult3, $matchresult4, $matchresult5, $matchresult6, $matchresult7, $matchresult8, $matchresult9); if($getAwayR == "Group A"){ $numWins = 0; for($i = 0; $i < count($matchInArray); i ++){ if($matchInArray[$i] == "W" && $numWins < 3){ $matchInArrayResu[$i] = "Qualified for Quarter Finals!"; $numWins++; } } } Quote Link to comment https://forums.phpfreaks.com/topic/252184-apply-condition-to-the-output-based-on-the-count-value/#findComment-1292942 Share on other sites More sharing options...
RON_ron Posted December 1, 2011 Author Share Posted December 1, 2011 $thanksGuys Quote Link to comment https://forums.phpfreaks.com/topic/252184-apply-condition-to-the-output-based-on-the-count-value/#findComment-1292945 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.