Example:
$a[] = \'56\';
$a[] = \'66\';
$a[] = \'\';
$a[] = \'58\';
$a[] = \'85\';
$a[] = \'\';
$a[] = \'\';
$a[] = \'76\';
$a[] = \'\';
$a[] = \'57\';
As a late look, item controls should be done with numeric check. Otherwise something like this $array = [1.2, 0.33, [123]] will corrupt the calculation:
// Get numerics only.
$array = array_filter($array, fn($v) => is_numeric($v));
// Get numerics only where value > 0.
$array = array_filter($array, fn($v) => is_numeric($v) && ($v > 0));
Finally:
public static function average(array $array, bool $includeEmpties = true): float
{
$array = array_filter($array, fn($v) => (
$includeEmpties ? is_numeric($v) : is_numeric($v) && ($v > 0)
));
return array_sum($array) / count($array);
}
Credits: froq.util.Arrays