У меня есть массив объектов, определенный аналогично приведенному ниже:
$scores = array();
// Bob round 1
$s = new RoundScore();
$s->Round_Name = 'Round 1';
$s->Player_Name = 'Bob';
$s->Score = 10;
$scores[0] = $s;
// Bob round 2
$s = new RoundScore();
$s->Round_Name = 'Round 2';
$s->Player_Name = 'Bob';
$s->Score = 7;
$scores[1] = $s;
// Jack round 1
$s = new RoundScore();
$s->Round_Name = 'Round 1';
$s->Player_Name = 'Jack';
$s->Score = 6;
$scores[2] = $s;
// Jack round 2
$s = new RoundScore();
$s->Round_Name = 'Round 2';
$s->Player_Name = 'Jack';
$s->Score = 12;
$scores[3] = $s;
Если я пройдусь по циклу и выгружу объект $scores
в таблицу, это будет выглядеть примерно так:
Round_Name Player Score ---------------------------- Round 1 Bob 10 Round 2 Bob 7 Round 1 Jack 6 Round 2 Jack 12
Однако я хочу что-то вроде этого:
Player Round 1 Round 2 Total ------------------------------- Bob 10 7 17 Jack 6 12 18
Я не буду знать заранее, сколько раундов или игроков будет, и скажем так, я не могу изменить способ построения объектов.
Какой самый эффективный способ сделать это в php?