Array
(
[0] => Array
(
[itemid] => 11
[kolvo] => 1
)
[1] => Array
(
[itemid] => 4309
[kolvo] => 1
)
[2] => Array
(
[itemid] => 11
[kolvo] => 1
)
[3] => Array
(
[itemid] => 4309
[kolvo] => 1
)
[4] => Array
(
[itemid] => 11
[kolvo] => 1
)
[5] => Array
(
[itemid] => 4309
[kolvo] => 1
)
[6] => Array
(
[itemid] => 2689
[kolvo] => 1
)
[7] => Array
(
[itemid] => 4445
[kolvo] => 1
)
[8] => Array
(
[itemid] => 10
[kolvo] => 1
)
[9] => Array
(
[itemid] => 3324
[kolvo] => 1
)
[10] => Array
(
[itemid] => 3372
[kolvo] => 1
)
)
foreach($items as $item) {
$massiv[] = array(
'itemid'=>$item[id],
'kolvo'=>1
);
}
Array
(
[0] => Array
(
[itemid] => 11
[kolvo] => 3
)
[1] => Array
(
[itemid] => 4309
[kolvo] => 3
)
[2] => Array
(
[itemid] => 2689
[kolvo] => 1
)
[3] => Array
(
[itemid] => 4445
[kolvo] => 1
)
[4] => Array
(
[itemid] => 10
[kolvo] => 1
)
[5] => Array
(
[itemid] => 3324
[kolvo] => 1
)
[6] => Array
(
[itemid] => 3372
[kolvo] => 1
)
)
// Для примера
$items = array (
array('id'=>3249),
array('id'=>11),
array('id'=>3249),
array('id'=>134),
array('id'=>11),
array('id'=>11),
array('id'=>542),
array('id'=>542),
array('id'=>542),
array('id'=>542),
array('id'=>542),
array('id'=>2546),
array('id'=>3849),
array('id'=>3249),
array('id'=>3249)
);
// End для примера
$result = array();
foreach($items as $item){
$result[] = array(
'kolvo'=>1,
'itemid'=>$item['id']
);
}
$grouped = [];
foreach ($result as $r) {
$key = $r['itemid'];
if (!isset($grouped[$key])) {
$grouped[$key] = $r;
} else {
$grouped[$key]['kolvo'] += $r['kolvo'];
}
}
sort($grouped);
natsort($grouped);
$grouped = array_reverse($grouped);
print_r($grouped);