Jump to content

two arrays in one loop?


RON_ron

Recommended Posts

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++;

        }

    }

}

Link to comment
Share on other sites

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++;
        }
    }
}

Link to comment
Share on other sites

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++;
	}
    }
}

Link to comment
Share on other sites

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.