JavaScript
1
Вклад в тег
<?php
$arr = [
array(
'id'=>1,
'number'=>5,
'id_public'=>1
),
array(
'id'=>2,
'number'=>3,
'id_public'=>1
),
array(
'id'=>3,
'number'=>2,
'id_public'=>2
),
array(
'id'=>4,
'number'=>2,
'id_public'=>4
),
array(
'id'=>5,
'number'=>1,
'id_public'=>4
)
];
$srch = 'number';
$unic = 'id_public';
$new_arr = [];
foreach ($arr as $value) {
if(!isset($new_arr[$value[$unic]]))$new_arr[$value[$unic]] = [0, 0];
$new_arr[$value[$unic]][0] += $value[$srch];//общее число
$new_arr[$value[$unic]][1]++;//количество повторов
}
$arr = [];
foreach($new_arr as $key => $value){
array_push($arr, array($unic=>$key, $srch=>$value[0]/$value[1]));
}
print_r($arr)
?>