我有一个文本文件。我想整理一些数据。例如。
UW have highest homescore 8.
JL have highest awayscore 8.
最大主场胜利。OH-AÖ 6-4 = 2
AH最大客场胜利KHS-AH 4-7 = 3
在一场比赛中得分最多的是UW-BS 8-7和CL-AB 7-8 =15
我快到了,我想知道一个人有多少次得分是13,哪里有重复的值,我想打印出四个或五个,现在我只显示一个值。
例如
UW 13三次MA 13两次最高分MA-JL 11-13
UW-BS 13-11氯-羟基12-12
按最高编号排序。
$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);
把这个给我
最高差异
Array
(
[hemmalag] => BS
[bortalag] => CM
[hemmares] => 12
[bortares] => 4
[diff] => 8
[sumres] => 16
)
最高分主场
Array
(
[hemmalag] => JS
[bortalag] => OH
[hemmares] => 13
[bortares] => 8
[diff] => 5
[sumres] => 21
)
得分最高的客场
Array
(
[hemmalag] => J�
[bortalag] => MA
[hemmares] => 11
[bortares] => 13
[diff] => 2
[sumres] => 24
)
最高总分
Array
(
[hemmalag] => J�
[bortalag] => MA
[hemmares] => 11
[bortares] => 13
[diff] => 2
[sumres] => 24
)
1条答案
按热度按时间jdgnovmf1#
我已经整理出如何得到得分为13的人。我添加了这个。
//查找最多的得分为13。