Array
(
[0] => Array
(
[id] => 1
[id_user] => 20
[count] => 2
[price] => 1000
)
[1] => Array
(
[id] => 2
[id_user] => 20
[count] => 5
[price] => 1000
)
[2] => Array
(
[id] => 3
[id_user] => 21
[count] => 3
[price] => 1000
)
[3] => Array
(
[id] => 4
[id_user] => 20
[count] => 3
[price] => 2000
)
[4] => Array
(
[id] => 5
[id_user] => 22
[count] => 3
[price] => 3500
)
[5] => Array
(
[id] => 6
[id_user] => 21
[count] => 10
[price] => 1000
)
)
======== результат,который хочется получить ==============
Array
(
[0] => Array
(
[id] => 1
[id_user] => 20
[count] => 17
[price] => 1000
)
[1] => Array
(
[id] => 4
[id_user] => 21
[count] => 13
[price] => 1000
)
[2] => Array
(
[id] => 2
[id_user] => 20
[count] => 4
[price] => 2000
)
[3] => Array
(
[id] => 5
[id_user] => 22
[count] => 3
[price] => 3500
)
)
$arr = [
['id' => 1, 'id_user' => 20, 'count' => 2, 'price' => 1000],
['id' => 2, 'id_user' => 20, 'count' => 5, 'price' => 1000],
['id' => 3, 'id_user' => 21, 'count' => 3, 'price' => 1000],
['id' => 4, 'id_user' => 20, 'count' => 3, 'price' => 2000],
['id' => 5, 'id_user' => 22, 'count' => 3, 'price' => 3500],
['id' => 6, 'id_user' => 21, 'count' => 10, 'price' => 1000],
];
foreach ($arr as $item) {
foreach ($arr as $item2) {
if ($item['price'] == $item2['price'] && $item['user_id'] == $item2['user_id'])
$merge_arr[]['count'] += $item2['count'];
// .............
}
}
// результат который хочется получить
$merge_arr = [
['id' => 1, 'id_user' => 20, 'count' => 17, 'price' => 1000],
['id' => 4, 'id_user' => 21, 'count' => 13, 'price' => 1000],
['id' => 2, 'id_user' => 20, 'count' => 4, 'price' => 2000],
['id' => 5, 'id_user' => 22, 'count' => 3, 'price' => 3500],
];
print_r($arr);
print_r($merge_arr);