Read data from textfile find highest score and find highest differnce between soccer result.. PHP

60 Views Asked by At

I have a text file. I want to sortout some data. For example.

UW  have highest homescore 8.
JL  have highest awayscore 8.

OH biggest home win . OH-AÖ 6-4 = 2

AH biggest away win KHS-AH 4-7 = 3

Most score in one match UW-BS 8-7 and CL-AB 7-8 =15

I'm almost there. I want to find out how many time a person have 13 in score, and where it is duplicate values I want to print out four or five of them . Right now I only show one value.

For example
UW 13 three times MA 13 two times Highest score MA-JL 11-13
UW-BS 13-11 CL-OH 12-12
sorted by highest number.

$array = explode("\n", file_get_contents($filename));
   
Array
   (
    [0] => 3/9
    [1] => AH-JL 6-8
    [2] => CM-PI 6-7
    [3] => OH-AÖ 6-4
    [4] => MF-PA 7-7
    [5] => PWB-HB 7-6
    [6] => JS-MA 6-6
    [7] => UW-BS 8-7
    [8] => JÖ-SMJ 7-6
    [9] => CL-AB 7-8
    [10] => CÅ-FG 7-7
    [11] => UL-KHS 7-7
    [12] => 
    [13] => 8/9
    [14] => PA-CM 5-7
    [15] => SMJ-PWB 5-6
    [16] => KHS-AH 4-7
    [17] => JL-CL 7-6
    [18] => UL-UW 7-6
    [19] => PI-JS 7-6
    [20] => BS-OH 7-6
    [21] => HB-MA 7-6
    [22] => AB-CÅ 7-7
    [23] => AÖ-MF 7-6
    [24] => FG-JÖ 5-6

function print_r2($matches){
    echo '<pre>';
    print_r($matches);
   echo  '</pre>'; 
}
    

$matchesLines = array ();
$statresultat = array ();
$test = array();
foreach($file as $line) {
    $antal +=1;
    //if(preg_match('/-/', $line)) 
    if(preg_match('/^([a-öA-Ö]+\D)-([a-öA-Ö]+\D) (\d+)-(\d+)/',  $line,  $data))
    {
        $Hemma_Lag = $data[1];
        $Borta_Lag= $data[2];
        $Hemma_Resultat = $data[3];
        $Borta_Resultat=$data[4];
        $Diff= abs($Borta_Resultat-$Hemma_Resultat);
        $Sumres= $Borta_Resultat + $Hemma_Resultat;
        $matchesLines1[]=array('hemmalag' =>$Hemma_Lag,
                                'bortalag' => $Borta_Lag,
                                'hemmares'=>$Hemma_Resultat,
                                'bortares'=>$Borta_Resultat,
                                'diff'=>$Diff,
                                'sumres' =>$Sumres);

       //$matchesLines[$Hemma_Lag]['hemmalag'];
       //$matchesLines[$Borta_Lag]['bortalag'];
   }
   //$statresultat[] =  $Hemma_Resultat."-".$Borta_Resultat;
}

$max = -9999999;
$maxhres = -9999999; //will hold max val
$maxbres = -9999999;

$maxsum = -9999999;
$maxratt = -9999999;

$found_item = null; //will hold item with max val;
$found_item1 = null;
$found_item2 = null;
$found_item3 = null;
$found_item4 = null;
foreach($matchesLines1 as $k=>$v) {
    if($v['diff']>$max) {
        $max = $v['diff'];
        $found_item = $v;
    }
    if($v['hemmares']>$maxhres) {
       $maxhres = $v['hemmares'];
       $found_item1 = $v;
    }
    if($v['bortares']>$maxbres) {
       $maxbres = $v['bortares'];
       $found_item2 = $v;
    }
    if($v['sumres']>$maxsum) {
       $maxsum = $v['sumres'];
       $found_item3 = $v;
    }
}  


echo "Highest diff";
print_r2($found_item);
echo "<br>";
echo "higherst score home";
print_r2($found_item1);
echo "<br>";
echo "higherst score away";
print_r2($found_item2);
echo "<br>";
echo "Higest sum score";
print_r2( $found_item3);

Get me this

Highest diff

  Array
  (
    [hemmalag] => BS
    [bortalag] => CM
    [hemmares] => 12
    [bortares] => 4
    [diff] => 8
    [sumres] => 16
  )

higherst score home

  Array
  (
    [hemmalag] => JS
    [bortalag] => OH
    [hemmares] => 13
    [bortares] => 8
    [diff] => 5
    [sumres] => 21 
  )

higherst score away

  Array
  (
    [hemmalag] => J�
    [bortalag] => MA
    [hemmares] => 11
    [bortares] => 13
    [diff] => 2
    [sumres] => 24
  )

Higest sum score

    Array
    (
    [hemmalag] => J�
    [bortalag] => MA
    [hemmares] => 11
    [bortares] => 13
    [diff] => 2
    [sumres] => 24
    )
1

There are 1 best solutions below

0
On

I have sorted out how to get the persons that have scored 13. I added this.

if($v['hemmares'] == $tretton|| $v['bortares'] == $tretton )
            {
                echo $v['hemmalag'] ;
                echo "-";
                echo $v['bortalag']; 
           
                echo"  ";
                echo $v['hemmares'];
                echo "-";   
                echo $v['bortares'];
                echo "<br>";
            }
        

// And for find most scored 13.

if($v['hemmares'] == $tretton )
    {
            $test1[]= $v['hemmalag'];
            
    }
           if($v['bortares'] == $tretton )
    {
         $test1[] = $v['bortalag'];
        
    }

//count array for duplicate
$count = array_count_values($test1);
//sort arrya 
arsort($count);
//print result.
print_r2($count);