I've searched a lot of examples with group/sum array values - unfortunately I can't resolve my problem. I got array $data which looks like this:
Array
(
[0] => Array
(
[0] => 1
[1] => 2014
[context] => 'aaa'
)
[1] => Array
(
[0] => 12
[1] => 2014
[context] => 'aaa'
)
[2] => Array
(
[0] => 5
[1] => 2014
[context] => 'zzz'
)
)
I would like to group and sum its values (but not all) by 'context'.
So desired output is:
Array
(
[0] => Array
(
[0] => 13
[1] => 2014
[context] => 'aaa'
)
[1] => Array
(
[0] => 5
[1] => 2014
[context] => 'zzz'
)
)
I'm far from this expected output. I've tried something like:
$result = array();
foreach ($data as $subArray)
{
foreach ($subArray as $row)
{
$result[$row['context']] = $row['context'];
$result[$row['1']] = $row['1'];
$result[$row['0']] += $row['0'];
}
}
But of course it doesn't work and I'm out of ideas. Can you please give me a hint? What else can I try?