Jump to content

FIFA WORLD CUP


blackend

Recommended Posts

hi

i am trying to write a program like fifa world cup groups. as you know it has 32 teams in 8 groups, each 4 .

i have an array for each group like this :

teams = array("brazil","germany","italy","sweden"); //temas in a group
nog = array("3","3","3","3");   //  number of games played
points = array("7","4","4","0"); //  points
gr = array("3","2","3","5");   // goals received . ( not the goal it has done)  

 

i want to choose first 2 teams. but it got difficult in some parts.

i want to choose the first and second team with the max point.    if the max point were equal i want to choose one with less gr (goal received) .

if the first team was the highest , but the 2 and 3 team were equal in points . choose from them which has the less gr .

if 2 teams were equal in all options : echo  stand by for teams  equal 1 and equal 2 .

 

can anyone help me with it ?

thanks

 

(if it is possible i want to check to number of games played , if  it were not 3 , then stop action , do nothing.  or if it was not 3 but if its team play the remaining games won't effect the result of 2  first team  then continue action)

i hope it is not a much thing to ask . 

 

 

Link to comment
https://forums.phpfreaks.com/topic/83019-fifa-world-cup/
Share on other sites

I'd rearrange my arrays and use

 

www.php.net/uasort

 

<?php
$teams = array (
            'italy' => array (
                            'nog' => 3,
                            'points' => 4,
                            'gr' => 3
                        ),
            'brazil' => array (
                            'nog' => 3,
                            'points' => 7,
                            'gr' => 3
                        ),
            'sweden' => array (
                            'nog' => 3,
                            'points' => 0,
                            'gr' => 5
                        ),
            'germany' => array (
                            'nog' => 3,
                            'points' => 4,
                            'gr' => 2
                        )
        );

function teamsort ($a, $b)
{
    if ($a['points']==$b['points'])                      // if equal on pts
    {
        return $a['gr'] - $b['gr'];                      // sort by gr ASCENDING
    }
    else return $b['points'] - $a['points'];             // otherwise sort on pts DESCENDING 
}

uasort ($teams, 'teamsort');                             // sort


echo '<pre>', print_r($teams, true), '</pre>';           // view sort results
?>

Link to comment
https://forums.phpfreaks.com/topic/83019-fifa-world-cup/#findComment-422282
Share on other sites

thanks for replying .

 

this function rearrange , and i can get the first 2 from the output array .

but

1. i can't find out if  2 teams are equal in all , then echo standby for team1 and team2 .  ?

2.i guess i should run in like , if each team played all its games (which is 3) . then compare them , OR if a team was in the group which did not play all its games, but if it played it won't effect the result , compare them and show result .

 

i  mean  :  (as every win is 3 points)      ((3 - nog) * 3 ) + points  <  maximum point of the group    // for checking if it matters that the team with less nog  plays or not .

 

 

 

i want to echo the first team as soon as the first team shows up , then echo the second as soon as it shows up .

 

(example :  italy wins all , get 9 points.  3 nog .    but all the other 3 didn't yet played .  so they are all nog 1 .  but they can never reach italy :  so i echo italy . then wait for others )

 

can you help me with that too ? (I UNDERSTAND I'M TAKING YOUR TIME, I'M SO GRATEFUL)

 

 

Link to comment
https://forums.phpfreaks.com/topic/83019-fifa-world-cup/#findComment-422290
Share on other sites

If you have this position, with italy and sweden yet to play then a win or draw by italy puts them 2nd and germany 3rd, so it's only necessary for (3-nog)*3 to exceed the points of the second team for the final 1st and 2nd placings to be unknown.

$teams = array (
            'italy' => array (
                            'nog' => 2,
                            'points' => 4,
                            'gr' => 3
                        ),
            'brazil' => array (
                            'nog' => 3,
                            'points' => 7,
                            'gr' => 3
                        ),
            'sweden' => array (
                            'nog' => 2,
                            'points' => 0,
                            'gr' => 5
                        ),
            'germany' => array (
                            'nog' => 3,
                            'points' => 4,
                            'gr' => 2
                        )
        );

Link to comment
https://forums.phpfreaks.com/topic/83019-fifa-world-cup/#findComment-422439
Share on other sites

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.