I have an array with dinamic value like this. the goal is merge array with have same code and sum of value with same code.
$array = array(
array(
array(
'code'=>'AA',
'name'=>'A Name',
'cost'=>'10',
),
array(
'code'=>'AB',
'name'=>'B Name',
'cost'=>'15',
),
),
array(
array(
'code'=>'AA',
'name'=>'A Name',
'cost'=>'15',
),
array(
'code'=>'AB',
'name'=>'B Name',
'cost'=>'10',
),
array(
'code'=>'AC',
'name'=>'C Name',
'cost'=>'10',
),
),
array(
array(
'code'=>'AA',
'name'=>'A Name',
'cost'=>'5',
),
array(
'code'=>'AB',
'name'=>'B Name',
'cost'=>'10',
),
array(
'code'=>'AC',
'name'=>'C Name',
'cost'=>'15',
),
),
);
And i want result like this
$result = array(
array(
array(
'code'=>'AA',
'name'=>'A Name',
'cost'=>'30',
),
array(
'code'=>'AB',
'name'=>'B Name',
'cost'=>'35',
),
),
);
The result is only code AA and BB because code AC not exist on first index. then code the same value to be sum.
Thanks