I have an array of objects defined as shown below:
$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;
If I loop and unload the $scores object into a table, it will look something like this:
Round_Name Player Score
----------------------------
Round 1 Bob 10
Round 2 Bob 7
Round 1 Jack 6
Round 2 Jack 12
I want, however, something like this:
Player Round 1 Round 2 Total
-------------------------------
Bob 10 7 17
Jack 6 12 18
I will not know in advance how many rounds or players will be, and let me say that I can not change the way objects are created.
What is the most efficient way to do this in php?
source share