Код: Выделить всё
$payments = [
['bookingId' => 1, 'vendorId' => 3, 'amount' => 50],
['bookingId' => 1, 'vendorId' => 3, 'amount' => 85],
['bookingId' => 1, 'vendorId' => 4, 'amount' => 14],
];
Код: Выделить всё
$payments = [
['bookingId' => 1, 'vendorId' => 3, 'amount' => 135],
['bookingId' => 1, 'vendorId' => 4, 'amount' => 14],
];
Код: Выделить всё
$output = [];
foreach($payments as $value) {
if(!array_key_exists($value['vendorId', $output))
$output[$value['vendorId'] = [
'bookingId' => $value['bookingId'],
'vendorId' => $value['vendorId'],
'amount' => $value['amount']
];
else
$output[$value['vendorId']['amount'] += $value['amount'];
}
$payments = array_values($output);
Подробнее здесь: https://stackoverflow.com/questions/637 ... ey-matches
Мобильная версия