<?php
$arr = range(1, 200);
$arr[50] = 0;
$arr[100] = 0;
$arr[150] = 0;
$arr[200] = 0;
$arr[99] = 9999;
$preparedArray = prepareArray($arr);
$sortedArray = sortArray($preparedArray);
showArray($sortedArray);
function prepareArray(array $arr)
{
$result = [];
$counter = 0;
$sum = 0;
foreach ($arr as $key => $value) {
if ($arr[$key] != 0) {
$counter++;
$sum += $value;
} else {
if ($counter != 0 and $sum / $counter > 20) {
$result[] = [
'sum' => $sum,
'counter' => $counter,
'key' => $key,
'intval' => intval($key / 30 / 60),
'proc' => $key / 30 % 60,
];
}
$counter = 0;
$sum = 0;
}
}
return $result;
}
function sortArray(array $arr)
{
usort($arr, function ($elem1, $elem2) {
return $elem1['sum'] <=> $elem2['sum'];
});
return $arr;
}
function showArray(array $arr)
{
foreach ($arr as $elem) {
echo $elem['sum'] . '/' . $elem['counter'] . ' (' . $elem['key'] . ') ' . $elem['intval'] . ':' . $elem['proc'] . "<br>";
}
}