Make a list of several football games and their football results. At the end, publish a chart showing the winning teams on top, drawing teams in the middle, losing teams at the bottom. The teams order will be determined by the gap they won or lost (highest ranking team won with the biggest gap, lowest ranking team lost with the biggest gap).
Solution #1
<?php
$gap=array();
$final=array();
$counter=0;
$games=array("Spain", "Brazil", "Argentina", "Russia", "China", "Italy", "Netherlands", "Portugal", "USA", "France", "Israel", "England", "Norway", "Germany");
$results=array(4, 3, 3, 1, 2, 1, 1, 1, 5, 2, 6, 0, 0, 0);
for ($x=0; $x<count($games)/2;$x++)
{
if ($results[$counter] > $results[$counter+1])
{
$gap[]=($results[$counter]-$results[$counter+1]);
$gap[]=($results[$counter+1]-$results[$counter]);
}
if ($results[$counter] == $results[$counter+1])
{
$gap[]=0;
$gap[]=0;
}
if ($results[$counter] < $results[$counter+1])
{
$gap[]=($results[$counter+1]-$results[$counter]);
$gap[]=($results[$counter]-$results[$counter+1]);
}
$counter++;
$counter++;
}
$final = array_combine($games, $gap);
arsort($final, SORT_NUMERIC);
print_r($final);
?>
No comments:
Post a Comment