Ho una matrice come risultato di una query di database. Le linee includono due dimensioni e alcune metriche. Le metriche devono essere sommate dai gruppi di dimensioni.PHP Raggruppamento di una matrice con più dimensioni dai risultati del database
Ecco un esempio grezzo array di dati in vista tabella:
Ecco dell'array esatta:
array(13) {
[0]=>
array(6) {
["source_name"]=>
string(8) "A"
["week"]=>
string(2) "10"
["picks"]=>
int(1)
["won"]=>
int(0)
["lost"]=>
int(1)
["draw"]=>
int(0)
}
[1]=>
array(6) {
["source_name"]=>
string(8) "A"
["week"]=>
string(2) "10"
["picks"]=>
int(1)
["won"]=>
int(1)
["lost"]=>
int(0)
["draw"]=>
int(0)
}
[2]=>
array(6) {
["source_name"]=>
string(8) "A"
["week"]=>
string(2) "11"
["picks"]=>
int(1)
["won"]=>
int(1)
["lost"]=>
int(0)
["draw"]=>
int(0)
}
[3]=>
array(6) {
["source_name"]=>
string(8) "A"
["week"]=>
string(2) "11"
["picks"]=>
int(1)
["won"]=>
int(1)
["lost"]=>
int(0)
["draw"]=>
int(0)
}
[4]=>
array(6) {
["source_name"]=>
string(8) "A"
["week"]=>
string(2) "11"
["picks"]=>
int(1)
["won"]=>
int(0)
["lost"]=>
int(1)
["draw"]=>
int(0)
}
[5]=>
array(6) {
["source_name"]=>
string(8) "A"
["week"]=>
string(2) "11"
["picks"]=>
int(1)
["won"]=>
int(0)
["lost"]=>
int(1)
["draw"]=>
int(0)
}
[6]=>
array(6) {
["source_name"]=>
string(8) "A"
["week"]=>
string(2) "11"
["picks"]=>
int(1)
["won"]=>
int(1)
["lost"]=>
int(0)
["draw"]=>
int(0)
}
[7]=>
array(6) {
["source_name"]=>
string(7) "B"
["week"]=>
string(2) "10"
["picks"]=>
int(1)
["won"]=>
int(0)
["lost"]=>
int(1)
["draw"]=>
int(0)
}
[8]=>
array(6) {
["source_name"]=>
string(7) "B"
["week"]=>
string(2) "10"
["picks"]=>
int(1)
["won"]=>
int(1)
["lost"]=>
int(0)
["draw"]=>
int(0)
}
[9]=>
array(6) {
["source_name"]=>
string(7) "B"
["week"]=>
string(2) "11"
["picks"]=>
int(1)
["won"]=>
int(0)
["lost"]=>
int(1)
["draw"]=>
int(0)
}
[10]=>
array(6) {
["source_name"]=>
string(7) "B"
["week"]=>
string(2) "11"
["picks"]=>
int(1)
["won"]=>
int(1)
["lost"]=>
int(0)
["draw"]=>
int(0)
}
[11]=>
array(6) {
["source_name"]=>
string(9) "C"
["week"]=>
string(2) "11"
["picks"]=>
int(1)
["won"]=>
int(1)
["lost"]=>
int(0)
["draw"]=>
int(0)
}
[12]=>
array(6) {
["source_name"]=>
string(9) "C"
["week"]=>
string(2) "11"
["picks"]=>
int(1)
["won"]=>
int(1)
["lost"]=>
int(0)
["draw"]=>
int(0)
}
}
Ecco quello che mi aspetto di ottenere in uscita:
Qual è il modo migliore per ottenere quell'output?
Grazie.
Quindi, loop sull'array e somma i valori in una nuova matrice. Non mi è chiaro dove sei bloccato. – GolezTrol
Questa matrice è il risultato di una query del database? – CodeGodie
@CodeGodie in realtà non riuscivo a capire come posso raggruppare e sommare senza loop multipli. E, sì, è il risultato di una query del database. – user1488895