0
I have the following array:
array(9) {
[0]=>
object(stdClass)#2477 (4) {
["type"]=>
string(2) "in"
["category"]=>
string(24) "Tratamento Odontológico"
["value"]=>
string(15) "333.33333333333"
}
[1]=>
object(stdClass)#2478 (4) {
["type"]=>
string(2) "in"
["category"]=>
string(24) "Tratamento Odontológico"
["value"]=>
string(15) "333.33333333333"
}
[2]=>
object(stdClass)#2479 (4) {
["type"]=>
string(2) "in"
["category"]=>
string(24) "Tratamento Odontológico"
["value"]=>
string(15) "333.33333333333"
}
[3]=>
object(stdClass)#2480 (4) {
["type"]=>
string(2) "in"
["category"]=>
string(24) "Tratamento Odontológico"
["value"]=>
string(15) "333.33333333333"
}
[4]=>
object(stdClass)#2481 (4) {
["type"]=>
string(2) "in"
["category"]=>
string(24) "Tratamento Odontológico"
["value"]=>
string(15) "333.33333333333"
}
[5]=>
object(stdClass)#2482 (4) {
["type"]=>
string(2) "out"
["category"]=>
string(24) "Contabilidade"
["value"]=>
string(15) "85.106382978723"
}
[6]=>
object(stdClass)#2483 (4) {
["type"]=>
string(2) "in"
["category"]=>
string(24) "Celular"
["value"]=>
string(15) "100"
}
[7]=>
object(stdClass)#2484 (4) {
["type"]=>
string(2) "in"
["category"]=>
string(24) "Celular"
["value"]=>
string(15) "100"
}
[8]=>
object(stdClass)#2485 (4) {
["type"]=>
string(2) "in"
["category"]=>
string(24) "Celular"
["value"]=>
string(15) "100"
}
}
I need to group the Category field so that only 1 item of each different category type is returned and add the values of each category. This needs to return, for example:
array(3) {
[0]=>
object(stdClass)#2477 (4) {
["type"]=>
string(2) "in"
["category"]=>
string(24) "Tratamento Odontológico"
["value"]=>
string(16) "1666,666666667"
}
[1]=>
object(stdClass)#2478 (4) {
["type"]=>
string(2) "out"
["category"]=>
string(24) "Contabilidade"
["value"]=>
string(15) "85.106382978723"
}
[2]=>
object(stdClass)#2479 (4) {
["type"]=>
string(2) "in"
["category"]=>
string(24) "Celular"
["value"]=>
string(15) "300"
}
}
I’ve researched and tried several ways to do this, but really I’m very lost and need help with this, thanks in advance!
Thank you very much! It’s just that I’m new to Laravel so I didn’t know the "Collections", I just had to use the $collection down and replace the $list and $item with the variable that receives the data from the bank, then did exactly what I needed! Thank you very much!!
– Caio