Domanda

I have been searching the archives for the better part of a full day and have not been able to find an answer to my question. I was hoping someone could point me in the right direction.

THE PROBLEM

Without being able to identify teams that are tied (duplicate win percentage) and logic to break those ties (outside scope of this question), I can't test head to head results and ultimately rank the teams correctly.

THE QUESTION

How do I:

  1. Identify which teams have the same win percentage (the number of total games played could differ for some teams)
  2. Count the number of teams that are tied.

EXAMPLE MULTIDIMENSIONAL ARRAY

I have a multidimensional array that stores arrays containing a team number, wins, losses, point differential, and win percentage.

Example:

$team_array = array(
array(68, 6, 0, 10, 1.000),
array(65, 6, 0, 8, 1.000),
array(62, 6, 0, 4, 1.000),
array(54, 3, 3, 3, .500),
array(55, 3, 3, -5, .500),
array(59, 0, 6, -16, .000)
);

I need help finding duplicate values in only 1 dimension of the multidimensional array (win percentage or $team_array[$x][4]. I do not know if it is better to try to find duplicate values or to eliminate unique values.

If anyone has any thoughts or suggestions, I would GREATLY appreciate it.

Thanks in advance!!!!

È stato utile?

Soluzione

Edit previous code didn't work.

// $seenDuplicate[ Percentage ][] = indexes which have this percentage.
foreach(team_array as $ind => $team){
    $trackPercentages[$team[4]][] = $ind;
}
// then you can count the number of each array in $trackPercentages

Reply to first comment: it's returning 3 because it contains all percentages regardless of duplication. The first is 1.000, second is .5000 and 3rd is .0000

foreach($trackPercentages as $perc => $list){
        $echo "Teams with " . $perc . "% wins.<br>";
        foreach($list as $team){
            echo $team."<br>";
        }
        echo "<br>";
}

if you only want to show duplicates, then right after first foreach loop, check:

if(count($list)>1)

And I believe ksort can be used to sort an array based on index.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top