How to group by column a and sum column b and c in a php array

Question

I got the following array:

[0] => Array
    (
        [kanel] => 5
        [peber] => 0
        [shipping] => A
    )

[1] => Array
    (
        [kanel] => 25
        [peber] => 0
        [shipping] => A
    )

[2] => Array
    (
        [kanel] => 25
        [peber] => 0
        [shipping] => C
    )

[3] => Array
    (
        [kanel] => 5
        [peber] => 0
        [shipping] => B
    )

[4] => Array
    (
        [kanel] => 5
        [peber] => 0
        [shipping] => C
    )

I want to print the following:

A Kanel: 30 Peber: 0

B Kanel: 5 Peber: 0

C Kanel: 30 Peber: 0

Literally grouping on shipping, sum on kanel and sum on peber as well.
I can find a lot on how to do it with one column, but it doesn’t do the trick. 🙂

Thank you!

0
Jannickla 3 weeks 2023-01-08T15:14:22-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse