I have this code and what i'm trying to do is , group the data coming from the .csv by Player , and then group by year and league , so for example , i will have faker -> 2021 -> lck->data ; ->2020->lck->data
and sometimes when a player has played more than one league in a year , faker->2021->lck->data | 2021->kespa->data
the problem is when i show the kills(image) , the year 2020 is adding the kills from 2021 plus kills from 2020. and what i want is 2020 show the kills from that league and that year and the same with 2021.
The result im Getting :
Faker => 2021 => kills [1,2,3] ; 2020 => kills [1,2,3,6,9,12];
The expected result is :
Faker => 2021 => kills [1,2,3] ; 2020 => kills [6,9,12]
how can i achieve that ?
Thats the csv
gameid,datacompleteness,url,league,year,split,playoffs,date,game,patch,playerid,side,position,player,team,champion .....
thats my code;
<?php
$csvFileData = file('./datalck.csv');
$dataMatch = [];
foreach ($csvFileData as $lines) {
$data[] = str_getcsv($lines);
}
foreach ($dataMatch as $matchs) {
// So here i'm grouping the array by player
//[3] is the position for the league
//[4] is the position for year
//[13] is the position of player name ,
//[23] The position of kills
if ($matchs[13] != NULL and $matchs[13] != "") {
$group[$matchs[13]][] = [
'Player' => $matchs[13],
"kills" => $matchs[23],
'league' => $matchs[3],
'year' => $matchs[4],
];
}
}
foreach ($group as $players => $p) {
$kills = [];
foreach ($p as $op) {
$kills[] = $op['kills'];
$group2[$op['Player']][$op['year']][$op['league']] = [
"Player" => $op['Player'],
"kills" => $kills,
"league" => $op['league'],
"year" => $op['year'],
];
}
}
foreach ($group2 as $op2) {
echo '<pre>';
var_dump(($group2));
echo '</pre>';
}
?>
