How to find average from array in php?

first you need to remove empty values, otherwise average will be not accurate.

so

$a = array_filter($a);
$average = array_sum($a)/count($a);
echo $average;

DEMO

More concise and recommended way

$a = array_filter($a);
if(count($a)) {
    echo $average = array_sum($a)/count($a);
}

See here

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)