$data1 = [
'id' => 1,
'quantity' => 10,
];
$data2 = [
'id' => 1,
'quantity' => 20,
];
$data3= [
'id' => 1,
'quantity' => 30,
];
<?php
$data1 = [
'id' => 1,
'quantity' => 10,
];
$data2 = [
'id' => 1,
'quantity' => 20,
];
function my_sum($all_data){
return array_reduce($all_data,function($a, $b)
{
$b['quantity'] = $a ? $b['quantity'] + $a['quantity']:$b['quantity'];
return $b;
});
}
$summ = my_sum([$data1,$data2]);
var_dump($summ);