$arr_id = [];
foreach ($row as $value) {
if (isset($arr_id[$value['id']])) {
$arr_id[$value['id']] += $value['num'];
continue;
}
$arr_id[$value['id']] = $value['num'];
}
$row = [];
foreach ( $arr_id as $key => $value) {
$row[] = [
'id' => $key;
'num' => $value;
];
}