The accepted answer works for example values, but generally just using array_filter($a) is probably not a good idea, because it will filter out any actual null values as well as strings with zero length.
Even '0' evaluates to false, so you should use a filter that explicitly excludes zero-length strings.
$a = array_filter($a, function($x) { return $x !== ''; }); $average = array_sum($a) / count($a);
source share