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
https://forums.phpfreaks.com/topic/252189-two-arrays-in-one-loop/
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++;
        }
    }
}

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

Archived

This topic is now archived and is closed to further replies.

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