Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Compare scores and echo out winners?

Comments in 'Plugin Development' started by Legoboy0215, Nov 27, 2015.

  1. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Basically, I have this code now:
    PHP:
    $kills = array();
            foreach([
    "blue""red""yellow""green"] as $color){
                
    $kills[$color] = $this->getTeam($color)->getKills();
            }
            
    arsort($kills);
    Now I have an array with the team names and their respective kills. Butt how would I check if 2, 3 or all 4 teams have the same amount of kills and echo that out?
  2. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Add this after your foreach loop, it will return the number of teams with the same number of kills
    PHP:
    max(array_count_values($kills));
    Legoboy0215 likes this.
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Not meaning to go off-topic, but I actually predicted you will be the one who would answer my question :p
  4. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    How would I echo out the teams that are tied or is the first?
  5. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Friendly bump. Not solved yet :(
  6. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    PHP:
    <?php
    $kills 
    = array("red" => 5,"blue" => 4,"yellow" => 3,"green" => 5);//for testing purpose
    $highest max($kills);//highest kills
    $t array_keys($kills,$highest);//teams with highest number of kills
    $c count($t);//number of teams with highest number of kills
    if($c 1){
        
    var_dump(implode(', ',$t)." have same amt of kills!");
    }else{
        
    var_dump(implode(' ',$t)." is first!");
    }
    AndrewBit and Legoboy0215 like this.

Share This Page

Advertisement