Array
(
[0] => Array
(
[id] => 1
[number] => 5
[id_public] => 1
)
[1] => Array
(
[id] => 2
[number] => 3
[id_public] => 1
)
[2] => Array
(
[id] => 3
[number] => 2
[id_public] => 2
)
[3] => Array
(
[id] => 4
[number] => 1
[id_public] => 2
)
[4] => Array
(
[id] => 5
[number] => 1
[id_public] => 4
)
)
Array
(
[0] => Array
(
[id] => 1
[number] => 4
[id_public] => 1
)
[1] => Array
(
[id] => 2
[number] => 2
[id_public] => 2
)
[2] => Array
(
[id] => 3
[number] => 1.5
[id_public] => 4
)
)
<?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)
?>